Friday, December 28, 2012

Linux command to list out all processes running on a port: lsof

lsof means list open files, which lists all disk files, pipes, network sockets and devices opened by all processes.

lsof -i:80 list out all the processes running on port 80.

 # lsof -i:80 
 
COMMAND   PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
apache2  2793 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3298 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3299 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3299 www-data   13u  IPv4 2991950      0t0  TCP li252-661.linod
apache2  3304 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3349 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3354 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3355 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3356 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3357 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2  3360 www-data    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)
apache2 25697     root    3u  IPv4 2500053      0t0  TCP *:http (LISTEN)

Friday, December 21, 2012

Linux Commands Help: grep

Find text in a file:

 For example to find out "404" requests( page not found ) in apache log file:

grep "404" /var/log/apache2/access.log
 The above command displays all the entries contains the word "404".
   

grep -n "404" /var/log/apache2/access.log
The above command displays all the entries contains the word "404" with line numbers.
   

grep -c "404" /var/log/apache2/access.log
The above command displays the no. of entries contains the word "404"

grep -c "404\|192.168.20.32" /var/log/apache2/access.log
The above command displays the no. of entries contains both the words "404" and "192.168.20.32"


Change Time Zone in MySQL

By default, MySQL uses timestamp of server.  

To check this, run 
SELECT @@global.time_zone, @@session.time_zone;

which returns "system";
  • Run the following command in terminal to change server timezone:
       sudo dpkg-reconfigure tzdata

         which prompts a dialog to change time zone:


  • Now restart mysql server: /etc/init.d/mysql restart
        Run "SELECT NOW();" query in MySQL editor, which should return the   time of modified time zone .