Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/sharedra...
File: sadatarunner.sh
#!/bin/bash
[0] Fix | Delete
# Shared RADS Tools, written by Erik Soroka (eriks@imhadmin.net, ext 834)
[1] Fix | Delete
# this script gets executed by crontab to collect sa accounting data for use by RADS tools
[2] Fix | Delete
[3] Fix | Delete
#lets set some variables
[4] Fix | Delete
YEAR=`date '+%Y'`
[5] Fix | Delete
MONTH=`date '+%b'`
[6] Fix | Delete
NUMMONTH=`date '+%m'`
[7] Fix | Delete
DAY=`date '+%d'`
[8] Fix | Delete
HOUR=`date '+%H'`
[9] Fix | Delete
[10] Fix | Delete
#create appropriate directories
[11] Fix | Delete
mkdir -p /var/log/sa/rads/$MONTH/$DAY
[12] Fix | Delete
mkdir -p /var/log/sa/rads/diskavail/
[13] Fix | Delete
mkdir -p /var/log/sa/rads/diskused/
[14] Fix | Delete
[15] Fix | Delete
#####################################################################
[16] Fix | Delete
### COLLECT AND ARCHIVE PROCESS ACCOUNTING DATA HERE
[17] Fix | Delete
#####################################################################
[18] Fix | Delete
[19] Fix | Delete
#output summary to file
[20] Fix | Delete
/usr/sbin/sa -mc > /var/log/sa/rads/$MONTH/$DAY/$HOUR-avg
[21] Fix | Delete
[22] Fix | Delete
#output totals to file
[23] Fix | Delete
/usr/sbin/sa -u > /var/log/sa/rads/$MONTH/$DAY/$HOUR
[24] Fix | Delete
[25] Fix | Delete
#compress files for optimal archival
[26] Fix | Delete
gzip -f /var/log/sa/rads/$MONTH/$DAY/$HOUR-avg
[27] Fix | Delete
gzip -f /var/log/sa/rads/$MONTH/$DAY/$HOUR
[28] Fix | Delete
[29] Fix | Delete
#####################################################################
[30] Fix | Delete
### FRESHEN YESTERDAY'S DATA. T3 TRAC #112
[31] Fix | Delete
#####################################################################
[32] Fix | Delete
[33] Fix | Delete
YESTERDAY_DAY=$(date --date='1 day ago' '+%d')
[34] Fix | Delete
YESTERDAY_MON=$(date --date='1 day ago' '+%b')
[35] Fix | Delete
YESTERDAY_YEAR=$(date --date='1 day ago' '+%Y')
[36] Fix | Delete
YESTERDAY_FIN_AVG='/var/log/sa/rads/'$YESTERDAY_MON'/'$YESTERDAY_DAY'/99-avg.gz'
[37] Fix | Delete
[38] Fix | Delete
#Which file has yesterday's data? CE6 uses a different naming convention
[39] Fix | Delete
ACCT_FILES[0]='/var/account/pacct.1'
[40] Fix | Delete
ACCT_FILES[1]="/var/account/pacct-${YEAR}${NUMMONTH}${DAY}"
[41] Fix | Delete
[42] Fix | Delete
# Find the one that exists
[43] Fix | Delete
for ACCT_FILE in ${ACCT_FILES[*]}; do
[44] Fix | Delete
if [[ -f $ACCT_FILE ]]; then
[45] Fix | Delete
YESTERDAY_ACCT_FILE=$ACCT_FILE
[46] Fix | Delete
fi
[47] Fix | Delete
done
[48] Fix | Delete
[49] Fix | Delete
#time's %s format doesn't return a float on anything I tested on, but
[50] Fix | Delete
#just in case, we'll pipe to cut
[51] Fix | Delete
YESTERDAY_ACCT_MTIME=$(date -r $YESTERDAY_ACCT_FILE '+%s' | cut -d. -f1)
[52] Fix | Delete
YESTERDAY_11TH_HOUR=$(date --date="$YESTERDAY_MON $YESTERDAY_DAY $YESTERDAY_YEAR 23:59" '+%s' | cut -d. -f1)
[53] Fix | Delete
[54] Fix | Delete
#if yesterday's acct file's mtime is not null (it would be if the file didn't exist)
[55] Fix | Delete
if [[ ! -z $YESTERDAY_ACCT_MTIME \
[56] Fix | Delete
#and yesterday's acct file has been modified since 23:59 yesterday
[57] Fix | Delete
&& $YESTERDAY_ACCT_MTIME -gt $YESTERDAY_11TH_HOUR \
[58] Fix | Delete
#and the final -avg.gz file doesn't already exist
[59] Fix | Delete
&& ! -f $YESTERDAY_FIN_AVG \
[60] Fix | Delete
#and a folder already exists for yesterday's saved sa data
[61] Fix | Delete
&& -d '/var/log/sa/rads/'$YESTERDAY_MON'/'$YESTERDAY_DAY ]]; then
[62] Fix | Delete
/usr/sbin/sa -mc -f $YESTERDAY_ACCT_FILE | gzip -c > $YESTERDAY_FIN_AVG
[63] Fix | Delete
fi
[64] Fix | Delete
[65] Fix | Delete
#####################################################################
[66] Fix | Delete
### COLLECT AND ARCHIVE DISK SPACE ACCOUNTING DATA HERE
[67] Fix | Delete
#####################################################################
[68] Fix | Delete
[69] Fix | Delete
#built in logic for varying partition tables across the shared fleet
[70] Fix | Delete
AREWEHOME=`/bin/df | /bin/grep '% /home$'`
[71] Fix | Delete
[72] Fix | Delete
if [ -z "$AREWEHOME" ]; then
[73] Fix | Delete
/bin/df | /bin/grep '% /$' | awk '{print $1,$4,$5}' > /var/log/sa/rads/diskavail/$DAY
[74] Fix | Delete
/bin/df | /bin/grep '% /$' | awk '{print $1,$3,$5}' > /var/log/sa/rads/diskused/$DAY
[75] Fix | Delete
else
[76] Fix | Delete
/bin/df | /bin/grep '% /home$' | awk '{print $1,$4,$5}' > /var/log/sa/rads/diskavail/$DAY
[77] Fix | Delete
/bin/df | /bin/grep '% /home$' | awk '{print $1,$3,$5}' > /var/log/sa/rads/diskused/$DAY
[78] Fix | Delete
fi
[79] Fix | Delete
[80] Fix | Delete
#####################################################################
[81] Fix | Delete
### CHECK FOR YUM SYSTEM UPDATES FOR LATER MONITORING
[82] Fix | Delete
#####################################################################
[83] Fix | Delete
[84] Fix | Delete
/usr/bin/yum check-update > /var/run/yum.check-update
[85] Fix | Delete
chown nagios.nagios /var/run/yum.check-update
[86] Fix | Delete
[87] Fix | Delete
#####################################################################
[88] Fix | Delete
### CHECK FOR DEFACEMENTS FROM ZONE-H FOR LATER MONITORING
[89] Fix | Delete
#####################################################################
[90] Fix | Delete
[91] Fix | Delete
TODAYIS=`date +%Y/%m/%d`
[92] Fix | Delete
MAINIPS=$(awk --re-interval '/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/{print $0}' /var/cpanel/mainip /var/cpanel/mainips/root | sort | uniq)
[93] Fix | Delete
> /var/log/.defacecounter
[94] Fix | Delete
for IPADDR in $MAINIPS; do
[95] Fix | Delete
HITS=`curl --connect-timeout 10 -s http://www.zone-h.org/archive/ip=$IPADDR | grep -c $TODAYIS`
[96] Fix | Delete
echo "$HITS $IPADDR" >> /var/log/.defacecounter
[97] Fix | Delete
done
[98] Fix | Delete
[99] Fix | Delete
[100] Fix | Delete
#####################################################################
[101] Fix | Delete
### CHECK FOR OVERSIZED DOMLOGS AND SEND IN STR'S FOR ACTION
[102] Fix | Delete
#####################################################################
[103] Fix | Delete
[104] Fix | Delete
/opt/sharedrads/extras/large_log_audit.sh 1>/dev/null 2>/dev/null
[105] Fix | Delete
[106] Fix | Delete
#####################################################################
[107] Fix | Delete
### ERROR CHECKING AND REPORTING
[108] Fix | Delete
#####################################################################
[109] Fix | Delete
[110] Fix | Delete
if [ -d "/var/log/sa/rads/$MONTH/$DAY" ]; then
[111] Fix | Delete
echo "OK"
[112] Fix | Delete
else
[113] Fix | Delete
echo "SA data runner failed to create archive directory: /var/log/sa/rads/$MONTH/$DAY -- Please investigate" | mail tier3@imhadmin.net -s "sadatarunner error: `hostname -s`"
[114] Fix | Delete
fi
[115] Fix | Delete
[116] Fix | Delete
## EOF ##
[117] Fix | Delete
[118] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function