I have a cron job which will copy some files and such. From time to time it will start failing due to an inaccessible host. When it starts failing, I'd like to get notified - but I don't want an email every 5 minutes telling me that the problem is ongoing.

I can think of ways to kludge up a solution, but I wonder if this functionality exists somewhere already? Server is OSX, but I only have shell access to it.

closed as off-topic by HopelessN00b Jan 22 '15 at 22:31

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

locked by HopelessN00b Jan 22 '15 at 22:31

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

Read more about locked posts here.

  • Also, there are several different kinds of failures - I'd like to be notified the first time any of them happens. – Steve Bennett Dec 16 '11 at 2:00
  • This question is off-topic under current topicality rules. – HopelessN00b Jan 22 '15 at 22:31

Well, a simple solution would be to just touch a "state" file upon first failure and notification. Then the next time the script runs, check for that state file and if it exists, then skip notification. Upon the next successful copy, remove the state file.

  • Yeah, that's reasonable. If failure { if !exists(fail_file) { notify } touch(fail_file) } else {delete(fail_file)} I could have a different file for each failure. – Steve Bennett Dec 16 '11 at 2:28
  • Ended up implementing this. It's simple. Set flag if failure file exists. Delete status file. Do stuff. If failure, compare to flag then send email. – Steve Bennett Jan 12 '12 at 4:24

Something like monit could potentially do what you want. Have your script write its errors to a file, then setup monit to send out an alert the first time the log becomes non-zero. The syntax is extremely flexible, so I am sure you could customize a definition to do exactly what you want.

# cront
0 0 0 0 0 root script 2>&1 > /var/scripts/myscript_state

#monit config
check file myscriptdata with path /var/scripts/myscript_state
   if changed size then alert

Not the answer you're looking for? Browse other questions tagged or ask your own question.