Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
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

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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