Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/maint/bin
File: logrunner.sh
#!/bin/bash
[0] Fix | Delete
[1] Fix | Delete
# create a temp file to hold our working queue
[2] Fix | Delete
queue=$(mktemp)
[3] Fix | Delete
[4] Fix | Delete
# clean up lastrun files that shouldn't exist
[5] Fix | Delete
for user in $(/bin/ls -A /var/cpanel/lastrun/); do
[6] Fix | Delete
if [ ! -f "/var/cpanel/users/$user" ]; then
[7] Fix | Delete
rm -rf "/var/cpanel/lastrun/$user"
[8] Fix | Delete
fi
[9] Fix | Delete
done
[10] Fix | Delete
[11] Fix | Delete
# get the number of cores on this box
[12] Fix | Delete
numcores=$(grep -c 'processor' /proc/cpuinfo)
[13] Fix | Delete
[14] Fix | Delete
# while there are out of date logs
[15] Fix | Delete
while [ "$(find /var/cpanel/lastrun -type f -mmin +1440|wc -l)" -gt 0 ]; do
[16] Fix | Delete
# build a queue file
[17] Fix | Delete
find /var/cpanel/lastrun -type f -mmin +1440 | awk -F/ '{print $5}' | sort -u > "$queue"
[18] Fix | Delete
[19] Fix | Delete
# while load's under $numcores and there are still users queued
[20] Fix | Delete
while [ "$(awk -F. '{print $1}' /proc/loadavg)" -lt "$numcores" ] && [ "$(wc -l "$queue" |awk '{print $1}')" -gt "0" ]; do
[21] Fix | Delete
# grab the first user in the queue
[22] Fix | Delete
user=$(head -1 "$queue")
[23] Fix | Delete
# remove said line from the queue
[24] Fix | Delete
sed -i '1d' "$queue"
[25] Fix | Delete
[26] Fix | Delete
# prepare a temp file for tracking
[27] Fix | Delete
userlog=$(mktemp)
[28] Fix | Delete
# run logs
[29] Fix | Delete
/scripts/runweblogs "$user" > "$userlog"
[30] Fix | Delete
[31] Fix | Delete
# grab output to make sure they processed
[32] Fix | Delete
bandwidthdone=$(grep -E -c "\.\.\.Done" "$userlog")
[33] Fix | Delete
statsdone=$(grep -E -c "^Complete" "$userlog")
[34] Fix | Delete
[35] Fix | Delete
# if they processed, update lastrun files
[36] Fix | Delete
if [ "$bandwidthdone" -gt "0" ]; then
[37] Fix | Delete
mkdir -p "/var/cpanel/lastrun/$user/"
[38] Fix | Delete
touch "/var/cpanel/lastrun/$user/bandwidth"
[39] Fix | Delete
fi
[40] Fix | Delete
if [ "$statsdone" -gt "0" ]; then
[41] Fix | Delete
mkdir -p "/var/cpanel/lastrun/$user/"
[42] Fix | Delete
touch "/var/cpanel/lastrun/$user/stats"
[43] Fix | Delete
fi
[44] Fix | Delete
if [ "$bandwidthdone" -gt "0" ] && [ "$statsdone" -gt "0" ]; then
[45] Fix | Delete
echo "Successfully processed logs for $user"
[46] Fix | Delete
else
[47] Fix | Delete
echo "Log processing for $user failed"
[48] Fix | Delete
fi
[49] Fix | Delete
[50] Fix | Delete
# clear our temp file for this user
[51] Fix | Delete
rm -f "$userlog"
[52] Fix | Delete
done
[53] Fix | Delete
# go to sleep if load's high
[54] Fix | Delete
echo "Load's too high, pausing for 60 seconds."
[55] Fix | Delete
sleep 60
[56] Fix | Delete
done
[57] Fix | Delete
[58] Fix | Delete
rm -f "$queue"
[59] Fix | Delete
[60] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function