Guest User

Untitled

a guest
May 19th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #!/bin/bash
  2. if pgrep "mysql" > /dev/null
  3. then
  4. echo "MYSQL Running"
  5. rm -f /var/run/.mysql_mail_sent
  6. else
  7. echo "ALERT: mysqld Stopped."
  8. if [ ! -f /var/run/.mysql_mail_sent ]; then
  9. echo "Sending MYSQL DOWN Email..."
  10. echo "DOWN ALERT! sending email" > /var/run/.mysql_mail_sent
  11.  
  12. fi
  13. fi
  14.  
  15. if pgrep "radiusd" > /dev/null
  16. then
  17. echo "radiusd Running"
  18. rm -f /var/run/.radiusd_mail_sent
  19. else
  20. echo "ALERT: RADIUSD Stopped"
  21. if [ ! -f /var/run/.radiusd_mail_sent ]; then
  22. echo "RADIUSD DOWN: Sending Email."
  23. echo "DOWN ALERT! sending email" > /var/run/.radiusd_mail_sent
  24. fi
  25. fi
  26.  
  27. #!/bin/bash
  28. # Scheduled Script to check linux service status after every 5 minutes.
  29. # If found stopped, send sms or email Alerts, but donot repeat it untill next status change.
  30. # Syed Jahanzaib
  31.  
  32.  
  33. # Run script with service name like
  34. # ./status.sh mysqld
  35.  
  36.  
  37. # Check if no service name is given
  38. if [ "$1" == "" ]; then
  39. echo No service name have been provided.
  40. echo Usage exmaple:
  41. echo
  42. echo -e "./status.sh mysqld"
  43. echo
  44. fi
  45.  
  46. DATE=`date`
  47. COMPANY="MYISP"
  48.  
  49.  
  50. SERVICE1="$1"
  51. SUBJECT="ALERT: $SERVICE1 is Down..."
  52. STATUS_HOLDER="/tmp/$SERVICE1_STATUS_HOLDER.txt"
  53.  
  54. # KANNEL Gateway Info
  55. KANNELURL="127.0.0.1:13013"
  56. KANNELID="kannel"
  57. KANNELPASS="password"
  58. CELL1="0333xxxxxx"
  59.  
  60. # SMS Msgs test
  61. MSG_UP="$COMPANY Info: $SERVICE1 is now UP @ $DATE"
  62. MSG_DOWN="$COMPANY Alert: $SERVICE1 is now DOWN @ $DATE"
  63.  
  64. touch $STATUS_HOLDER
  65.  
  66. for SRVCHK in $SERVICE1
  67. do
  68. PID=$(pgrep $SERVICE1)
  69. if [ "$PID" == "" ]; then
  70. echo "$SRVCHK is down"
  71. if [ $(grep -c "$SRVCHK" "$STATUS_HOLDER") -eq 0 ]; then
  72. echo "ALERT: $SERVICE1 is down at $(date) / SENDING SMS ...."
  73. echo "$MSG_DOWN" > /tmp/$SERVICE1_down.sms
  74. # Sending DOWN SMS via KANNEL
  75. cat /tmp/$SERVICE1_up.sms | curl "http://$KANNELURL/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$CELL1" -G --data-urlencode text@-
  76. echo "$SRVCHK" >> $STATUS_HOLDER
  77. fi
  78. else
  79. echo -e "$SRVCHK is alive and its PID are as follows...n$PID"
  80. if [ $(grep -c "$SRVCHK" "$STATUS_HOLDER") -eq 1 ]; then
  81. echo "INFO ALERT : $SERVICE1 is UP at $(date) / SENDING SMS ...."
  82. echo "$MSG_UP" > /tmp/$SERVICE1_up.sms
  83. # Sending UP SMS via KANNEL
  84. cat /tmp/$SERVICE1_up.sms | curl "http://$KANNELURL/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$CELL1" -G --data-urlencode text@-
  85. sed -i "/$SRVCHK/d" "$STATUS_HOLDER"
  86. fi
  87. fi
  88. done
Add Comment
Please, Sign In to add comment