Monday, 2 June 2008

Full Disk Check - Notify

Another stupid little script written with the same principle as the previous ones to notify the administrator when a drive reaches 99% usage.
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin

FULL_DRIVES=`df -h | grep "99%"`
SPACE_USE=`echo $FULL_DRIVES | awk '{print $5}'`
PERCENT=`echo ${SPACE_USE%%%}`

if [ "$PERCENT" = "99" ]
then
wget "http://api.clickatell.com/http/auth?api_id=yourapi_id&user=usrname&password=passwd" -O /tmp/sessionid -q
# Create session and save to /tmp/sessionid
sessionid=`cat /tmp/sessionid | awk '{print $2}'`
# use only the session id for the variable
smssend clickatell.sms $sessionid usrname passwd yourapi_id "SystemAlert" phoneNo "$FULL_DRIVES"
# send sms
else
echo "No disks have reached critical usage"
fi

The previous articles can be found here and here

Thanks for playing :)