Short version: Is there an off-the-shelf program to avoid being pinged repeatedly be frequent cron jobs in periods when they fail? I have a custom implementation but it seems like something someone would have dealt with already.

I have a script on my home server to fetch my mail from my ISP server to store locally. More often than I'd like, Comcast goes down for an hour or so and I get dozens of messages from cron (one every two minutes) reporting that fetchmail failed. I set up a script to read the output of the cron job (blank on success) and always put it into a log file, but only put it to stdout -- and, therefore, my email -- if it's been at least 20 minutes since the last error occurred.

I can't be the only sysadmin with this issue. In short, the job runs frequently and I only want periodic updates while it's failing, not a constant stream of errors. Is there an off-the-shelf solution that I've missed?

Script is as follows; As you can see it's pretty basic, e.g. no indication when the errors stop:


cat >> "${latestlogpath}"
([ ! -e "${logpath}" ] || [[ $(date +%s -r "${logpath}") -lt $(date +%s --date="${minutes} min ago") ]] ) && {
  cat "${latestlogpath}"
  cat "${latestlogpath}" >> "${logpath}"
  rm "${latestlogpath}"
  • Strangely enough, email client on my laptop does this quite perfectly out of the box by redirecting repeated messages to Spam folder. (It's MS Outlook 2010 shhhhhhh...) – kubanczyk Feb 26 '16 at 20:51
  • What I have done in the past is actually probably over-engineered, but I use a SQLite database to track failures, and if I have had more than n failures over a given period, I don't send a notification email (or, in a cron context, not output to stderr). – DopeGhoti Feb 26 '16 at 21:37
  • 1
    IMO you are looking in the wrong place. Instead of thinking about some magic way to suppress cron logging I'd advise: - Implement fetchmail logging to the separate file you are not using for your notification system. For example : /var/log/fetchmail.log - Create a shell script which will be periodically (cron) analysing the fetchmail file and using criteria like error count etc. it will log an error to the syslog. – KWubbufetowicz Feb 27 '16 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.