Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if pgrep "mysql" > /dev/null
- then
- echo "MYSQL Running"
- rm -f /var/run/.mysql_mail_sent
- else
- echo "ALERT: mysqld Stopped."
- if [ ! -f /var/run/.mysql_mail_sent ]; then
- echo "Sending MYSQL DOWN Email..."
- echo "DOWN ALERT! sending email" > /var/run/.mysql_mail_sent
- fi
- fi
- if pgrep "radiusd" > /dev/null
- then
- echo "radiusd Running"
- rm -f /var/run/.radiusd_mail_sent
- else
- echo "ALERT: RADIUSD Stopped"
- if [ ! -f /var/run/.radiusd_mail_sent ]; then
- echo "RADIUSD DOWN: Sending Email."
- echo "DOWN ALERT! sending email" > /var/run/.radiusd_mail_sent
- fi
- fi
- #!/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
Add Comment
Please, Sign In to add comment