Wednesday, August 20, 2008

Sned sms server status reports to you mobile phone

Add following entries to /etc/crontab

10  *   * * *   root /bin/bash /path/to/alert.sh
10  20  * * *   root /bin/bash /path/to/info.sh

alert.sh:

#!/bin/bash
MESSAGE=""
APACHE=$(ps aux | grep apache | grep -v 'grep' | wc -l)
MYSQL=$(ps aux | grep mysql | grep -v 'grep' | wc -l)

MESSAGE="A:$APACHE,M:$MYSQL"

if [[ $MYSQL == "0" || $APACHE == "0" ]]; then
sms -r r1 -u your_name -p your_password -m "$MESSAGE"
else
echo "$MESSAGE"
fi



info.sh:

#!/bin/bash
SPACE=$( df -h /var | grep var | awk '{print $4}' )
UPTIME=$( uptime | awk '{print $3}' )
WHO=$( who | awk '{print $1}' )
APACHE=$(ps aux | grep apache | grep -v 'grep' | wc -l)
MYSQL=$(ps aux | grep mysql | grep -v 'grep' | wc -l)

MESSAGE="S:$SPACE,U:$UPTIME,W:$WHO,A:$APACHE,M:$MYSQL"
echo $MESSAGE

sms -r r1 -u yourname -p your_password -m "$MESSAGE"
Blogged with the Flock Browser

No comments:

Post a Comment