Ok, finalmente consegui. O BASH é mais rápido e não requer nenhuma ferramenta de 3ª parte. [atualizado 4:43 pm]
#!/bin/bash
# Scheduled Script to check linux service status after every 5 minutes.
# If found stopped, send sms or email Alerts, but donot repeat it untill next status change.
# Syed Jahanzaib
# Run script with service name like
# ./status.sh mysqld
# Check if no service name is given
if [ "$1" == "" ]; then
echo No service name have been provided.
echo Usage exmaple:
echo
echo -e "./status.sh mysqld"
echo
fi
DATE='date'
COMPANY="MYISP"
SERVICE1="$1"
SUBJECT="ALERT: $SERVICE1 is Down..."
STATUS_HOLDER="/tmp/$SERVICE1_STATUS_HOLDER.txt"
# KANNEL Gateway Info
KANNELURL="127.0.0.1:13013"
KANNELID="kannel"
KANNELPASS="password"
CELL1="0333xxxxxx"
# SMS Msgs test
MSG_UP="$COMPANY Info: $SERVICE1 is now UP @ $DATE"
MSG_DOWN="$COMPANY Alert: $SERVICE1 is now DOWN @ $DATE"
touch $STATUS_HOLDER
for SRVCHK in $SERVICE1
do
PID=$(pgrep $SERVICE1)
if [ "$PID" == "" ]; then
echo "$SRVCHK is down"
if [ $(grep -c "$SRVCHK" "$STATUS_HOLDER") -eq 0 ]; then
echo "ALERT: $SERVICE1 is down at $(date) / SENDING SMS ...."
echo "$MSG_DOWN" > /tmp/$SERVICE1_down.sms
# Sending DOWN SMS via KANNEL
cat /tmp/$SERVICE1_up.sms | curl "http://$KANNELURL/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$CELL1" -G --data-urlencode text@-
echo "$SRVCHK" >> $STATUS_HOLDER
fi
else
echo -e "$SRVCHK is alive and its PID are as follows...\n$PID"
if [ $(grep -c "$SRVCHK" "$STATUS_HOLDER") -eq 1 ]; then
echo "INFO ALERT : $SERVICE1 is UP at $(date) / SENDING SMS ...."
echo "$MSG_UP" > /tmp/$SERVICE1_up.sms
# Sending UP SMS via KANNEL
cat /tmp/$SERVICE1_up.sms | curl "http://$KANNELURL/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$CELL1" -G --data-urlencode text@-
sed -i "/$SRVCHK/d" "$STATUS_HOLDER"
fi
fi
done