Thursday, March 14, 2013

Admin useful commands


1.
Top 20 memory consuming processes.
ps -eo pmem,pid,user,args | sort -k 1 -g -r | head -20

2.
Top 20 cpu consuming processes.
ps -eo pcpu,pid,user,args | sort -k 1 -g -r | head -20

3.
See the IP addresses accessing php files. This will work only in servers running php as CGI.

ps aeuxf | grep php|awk -F'REMOTE_ADDR=' '{ print $2 }' |cut -d\ -f 1 | uniq -c | sed 's/^[ ]*//'
Sample outout::

26 87.250.255.241
4.
To get the active php processes running on the server.

ps aeuxf | grep php | awk -F'SCRIPT_FILENAME=' '{ print $2 }' |cut -d\ -f 1 | uniq -c | sed 's/^[ ]*//'

Sample outout::

1 /home/blogfil/public_html/index.php
5.
To list the php processes and the time they have been running on the server.

ps -eo pid,cmd,etime,args --sort:etime | grep php

Sample outout::
2050 /usr/bin/php /home/macroren 33-23:22:32 /usr/bin/php /home/macroren/public_html/wp-cron.php
This means the php process of user macroren has been running on the server for 33 days, 23 hours, 22 minutes and 32 seconds.
This way you can kill the old processes and save mem/cpu

No comments:

Post a Comment