Here are a list of useful commands for everyone under the sun to do their work easily with cPanel
cPanel Resource Usage Stats
To view cPanel’s stats you can run this command via SSH:
/usr/local/cpanel/bin/dcpumonview
This will show all processes, users, etc.
Get cPanel Resource Stats for X Days
If you want to get the stats for a user for say the past 5 days or so, run this command in SSH:
domain="thedomain.com"; for i in `seq 1 7 `; do let i=$i+1 ; let k=$i-1 ; let s="$(date +%s) - (k-1)*86400"; let t="$(date +%s) - (k-2)*86400"; echo `date -Idate -d @$s`; /usr/local/cpanel/bin/dcpumonview `date -d @$s +%s` `date -d @$t +%s` | sed -r -e 's@^<tr bgcolor=#[[:xdigit:]]+><td>(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td></tr>$@Account: \1\tDomain: \2\tCPU: \3\tMem: \4\tMySQL: \5@' -e 's@^<tr><td>Top Process</td><td>(.*)</td><td colspan=3>(.*)</td></tr>$@\1 - \2@' | grep $domain -A3 ; done
Script to find cPanel account and its corresponding IP address
cat /etc/userdatadomains | perl -pi -e "s/^.*? //," | perl -pi -e "s/==.*==6/ 6/," | perl -pi -e "s/:80==//," | sort | uniq
cPanel script to assign IP via shell: /usr/local/cpanel/bin/setsiteip -u username IPaddress
Courtesy of https://sites.google.com/site/pleskylinuxcom/bash-scripting
If you want to just monitor a specific user and not access the logs you can do so with these commands:
Monitor specific user using TOP
top -c d2 -u username
Monitor all users using TOP
top -c d2
Alternately you can use htop instead of top if you have it installed.
Script to delete Big file
#!/bin/bash find /home -name '*.DS_Store' -type f -delete & find /home -name '*.swp' -type f -delete & find /home -name '*.swo' -type f -delete & find /home -name 'error_log' -size +10M -type f -delete & find /home -type f -name '*' -size +500M -exec rm -if {} \; &
In case you are wondering, anything bigger than 500M
find spammer script in cpanel
grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F "cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n
the above will look for script that is spamming your cpanel server
find 10 biggest disk user in cpanel
find /home -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
the above will search for the 10 biggest folder used by your user
Clear Exim Mail Queue
exiqgrep -zi|xargs exim -Mrm
this will clear all your exim queue to sparkling clean.
Delete cPanel email more than 2 years
find -P /home/*/mail/*/*/cur -mtime '+729';find -P /home/*/mail/*/*/new -mtime '+729'
firing above will delete all email that is bigger than 729 day
check for all unique ip connected to your server
netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c | sort -n
useful when you are getting DDOS