server status

hi all -

when i first started up with interserver, i kept running out of disk space and/or memory. so i wrote this bash script (below)

so now every couple of hours i get an email with a subject line that looks like this:

Memory: 828 mb 65% -- Disk: 45% Boot: Mar 11 19:35

and this line is in my crontab:
Code:
0 */2 * * *     /bin/bash -vx   /usr/local/bash/serverUtilization.bsh   >> /tmp/cron    2>/dev/null
there is probably a better way to do this. suggestions? ideas? complaints? free lunch offers?



Code:
#! /bin/bash -w
 
TOTAL=$(/usr/bin/free  -m   |  grep  "^Mem:" | sed -e 's/^Mem: * \([0-9]*\) * \([0-9]*\) *\([0-9]*\).*$/\1/';  );
REMAIN=$(/usr/bin/free  -m  |  grep  "^Mem:" | sed -e 's/^Mem: * \([0-9]*\) * \([0-9]*\) *\([0-9]*\).*$/\2/';  );
FREE=$(/usr/bin/free  -m    |  grep  "^Mem:" | sed -e 's/^Mem: * \([0-9]*\) * \([0-9]*\) *\([0-9]*\).*$/\3/';  );
PERCENT=$(echo "scale=2; $REMAIN / $TOTAL * 100 " | bc | sed -e 's/\.00//;' ; );
 
SUBJECT=$(      (       /bin/echo 'Memory: '  ;       \
                        /bin/echo ${FREE} ' mb '    ;       \
                        /bin/echo ${PERCENT}% ' -- '  ;       \
                        /bin/echo ' Disk: '                 ;       \
                        /bin/df  |  grep  simfs  | sed -e  's?^.*\([0-9][0-9]%\).*$?\1?'  ;       \
                        /usr/bin/who -b | sed -e  's/.*system//;s/boot/ Boot:/'     ;       \
                )                      \
        |       /usr//bin/tr '\n' ' '     ;       \
        );
#
echo '' | /bin/mail -r 'Marky Edwards <mark@domain.com>'  -s "$SUBJECT" mark@domain.com  >> /tmp/cron ;
#
 
Top