How can I create a bash script for MySQL status/replication that only notifies of failure once per hour?

I am using CentOS 6.2.

I followed Alex Williams guide to configuring MySQL through HAProxy found here.

Instead of having HAProxy check the status of MySQL and replication, I have the scripts running once a minute in crontab. If either of them fails I have them echo the failure to a text file; /opt/repl.txt or /opt/mysql.txt.

I have a script that checks if these files exist, and if so sends out an email notifying personnel that the failure occurred. This is also configured in crontab to run once a minute.

Basically, what I am trying to accomplished is this; I would like the script to only send out the emails at the initial failure, and once an hour after that until the issue is resolved. I am not entirely sure how to do this with bash scripting. The last time something failed it was sending out an email a minute about it, and that is definitely not what I’d like to have happen. Any help would be much appreciated.

Answer

Modify your script to touch a file when it sends an email and to not send an email if the file is < 1 hour old.

Attribution
Source : Link , Question Author : Joe Gibson , Answer Author : Chris Nava

Leave a Comment