I have a following script scheduled to run every 5 minute that checks for two services and if it found any service status down,it sends email. Its working ok.
But the issue is I want it to send UP alert as well when service goes up. I can add line to send email but it repeats the up alert. how can i add UP alert function but it should send alert just one time (like it do for down alert)
#!/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