Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/smshex_r.../opt/sharedra...
File: rescp.sh
#!/bin/bash
[0] Fix | Delete
[1] Fix | Delete
USER=$1
[2] Fix | Delete
SESSIONID=`date +%s`
[3] Fix | Delete
CHILDACCTS=`/bin/grep -rl OWNER=$USER /var/cpanel/users|cut -d/ -f5`
[4] Fix | Delete
[5] Fix | Delete
if [ -z $1 ]; then
[6] Fix | Delete
[7] Fix | Delete
# No reseller inputted, display top resellers sorted by cumulative CP #
[8] Fix | Delete
[9] Fix | Delete
touch /tmp/sumrescp.$SESSIONID
[10] Fix | Delete
touch /tmp/rescp.$SESSIONID
[11] Fix | Delete
[12] Fix | Delete
sa -cm |awk '{print $1,$6}' > /tmp/sadata.$SESSIONID
[13] Fix | Delete
[14] Fix | Delete
cat /tmp/sadata.$SESSIONID| while read line; do
[15] Fix | Delete
ruser=$(echo $line|awk '{print $1}')
[16] Fix | Delete
rusercp=$(echo $line|sed 's/[A-Za-z]*//g'|awk '{print $NF}')
[17] Fix | Delete
rparent=$(grep OWNER /var/cpanel/users/$ruser 2>/dev/null|cut -d= -f2)
[18] Fix | Delete
echo "$rparent $rusercp" >> /tmp/rescp.$SESSIONID
[19] Fix | Delete
done
[20] Fix | Delete
[21] Fix | Delete
awk '{arr[$1]+=$2;} END {for (i in arr) print i, arr[i]}' /tmp/rescp.$SESSIONID > /tmp/sumrescp.$SESSIONID
[22] Fix | Delete
[23] Fix | Delete
echo
[24] Fix | Delete
echo -e "Top 15 resellers sorted by CP used so far today:"
[25] Fix | Delete
echo
[26] Fix | Delete
cat /tmp/sumrescp.$SESSIONID |egrep -v "root|nobody|mailnull|inmotion|cpanellogin|clamav|dovenull|nagios|cpanel" |sort -nk2 |tail -15 |tac|sed 's/$/cp/'|column -t
[27] Fix | Delete
echo
[28] Fix | Delete
[29] Fix | Delete
else
[30] Fix | Delete
[31] Fix | Delete
###############################################
[32] Fix | Delete
# Showing cumulative CP for specific reseller #
[33] Fix | Delete
###############################################
[34] Fix | Delete
[35] Fix | Delete
if [[ `grep OWNER /var/cpanel/users/$USER -s` = "OWNER=inmotion" ]]; then
[36] Fix | Delete
ALLACCTS=$( echo "$CHILDACCTS"; echo "$USER")
[37] Fix | Delete
echo
[38] Fix | Delete
echo -e " Cumulative CP usage of reseller: $USER"
[39] Fix | Delete
echo -ne " Total # of child accounts: "
[40] Fix | Delete
echo "$CHILDACCTS"|wc -l
[41] Fix | Delete
echo -ne " Total CP used today (`date --date="today"| awk '{print $2,$3}'`): "
[42] Fix | Delete
sa -cm |egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[43] Fix | Delete
echo -ne "cp"
[44] Fix | Delete
echo
[45] Fix | Delete
echo
[46] Fix | Delete
[47] Fix | Delete
echo "Historical cumulative CPU usage"
[48] Fix | Delete
[49] Fix | Delete
DAY1=$(echo "`date +"%b/%d" --date="-1 days"`")
[50] Fix | Delete
echo -n " $DAY1 :: "
[51] Fix | Delete
zcat /var/log/sa/rads/$DAY1/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[52] Fix | Delete
echo -ne "cp"
[53] Fix | Delete
echo
[54] Fix | Delete
[55] Fix | Delete
DAY2=$(echo "`date +"%b/%d" --date="-2 days"`")
[56] Fix | Delete
echo -n " $DAY2 :: "
[57] Fix | Delete
zcat /var/log/sa/rads/$DAY2/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[58] Fix | Delete
echo -ne "cp"
[59] Fix | Delete
echo
[60] Fix | Delete
[61] Fix | Delete
DAY3=$(echo "`date +"%b/%d" --date="-3 days"`")
[62] Fix | Delete
echo -n " $DAY3 :: "
[63] Fix | Delete
zcat /var/log/sa/rads/$DAY3/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[64] Fix | Delete
echo -ne "cp"
[65] Fix | Delete
echo
[66] Fix | Delete
[67] Fix | Delete
DAY4=$(echo "`date +"%b/%d" --date="-4 days"`")
[68] Fix | Delete
echo -n " $DAY4 :: "
[69] Fix | Delete
zcat /var/log/sa/rads/$DAY4/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[70] Fix | Delete
echo -ne "cp"
[71] Fix | Delete
echo
[72] Fix | Delete
[73] Fix | Delete
DAY5=$(echo "`date +"%b/%d" --date="-5 days"`")
[74] Fix | Delete
echo -n " $DAY5 :: "
[75] Fix | Delete
zcat /var/log/sa/rads/$DAY5/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[76] Fix | Delete
echo -ne "cp"
[77] Fix | Delete
echo
[78] Fix | Delete
[79] Fix | Delete
DAY6=$(echo "`date +"%b/%d" --date="-6 days"`")
[80] Fix | Delete
echo -n " $DAY6 :: "
[81] Fix | Delete
zcat /var/log/sa/rads/$DAY6/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[82] Fix | Delete
echo -ne "cp"
[83] Fix | Delete
echo
[84] Fix | Delete
[85] Fix | Delete
DAY7=$(echo "`date +"%b/%d" --date="-7 days"`")
[86] Fix | Delete
echo -n " $DAY7 :: "
[87] Fix | Delete
zcat /var/log/sa/rads/$DAY7/21-avg.gz | egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{s+=$6} END {printf "%.0f", s}'
[88] Fix | Delete
echo -ne "cp"
[89] Fix | Delete
[90] Fix | Delete
echo
[91] Fix | Delete
echo
[92] Fix | Delete
echo "Displaying top 20 child accounts sorted by CP for reseller ($USER): "
[93] Fix | Delete
echo
[94] Fix | Delete
sa -cm |egrep -w `echo $ALLACCTS|sed ':a;N;$!ba;s/\n/ /g'|sed 's# #|#g'`|awk '{print " "$1,$6}'|head -20|column -t
[95] Fix | Delete
echo
[96] Fix | Delete
[97] Fix | Delete
else
[98] Fix | Delete
echo
[99] Fix | Delete
[100] Fix | Delete
# Display error/help message
[101] Fix | Delete
echo "rescp.sh - A script made to help identify reseller accounts that are consuming a large amount of CP"
[102] Fix | Delete
echo
[103] Fix | Delete
echo "Usage:"
[104] Fix | Delete
echo " Option 1.) Run script with no arguments (calculates cumulative CP usage for reseller users across the server)"
[105] Fix | Delete
echo " Option 2.) Run script with a reseller username (see children with the highest CP)"
[106] Fix | Delete
echo
[107] Fix | Delete
fi
[108] Fix | Delete
[109] Fix | Delete
fi
[110] Fix | Delete
[111] Fix | Delete
# Remove temporary files
[112] Fix | Delete
rm -f /tmp/rescp.$SESSIONID
[113] Fix | Delete
rm -f /tmp/sumrescp.$SESSIONID
[114] Fix | Delete
rm -f /tmp/sadata.$SESSIONID
[115] Fix | Delete
[116] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function