0

I know it's possible to do this yourself, but I figured I'd see if anyone knew of something that works like this imaginary command, throttle-check:

check_server_is_ok || throttle-check some_unique-command-key '1 hour' &&\
send_spammy_email

So, throttle-check returns true the first time it is run with a particular key, and then no more than once every <time period> after that.

My use case is a cron job that monitors something that I want to check quite frequently, and send an email as soon as there's a problem, but then not keep spamming the email every time there's a problem.

The command would need to store some persistent state somewhere, I'm pretty sure.

If nobody knows of a nice command I'll just write my own :)

  • What if you create a temp file whenever you find it for the first time? And every time you check the condition, check if the file exists or not. If it does, do not trigger the email. – fedorqui Oct 17 '13 at 08:54
  • Could do. I'd also need to compare the timestamp on that file and do some date math, to ensure that the command keeps happening on an interval. I'm sure it's doable, I just was wondering if it's been done already. – Aaron Sokoloski Oct 17 '13 at 08:57
  • 1
    What about this: 1) in case of `error + no file` -> touch file 2) in case of `error + file` -> do nothing 3) in case of `no error` -> delete file if exists. This way you will just get an email when there is a change from `working` to `not working`. – fedorqui Oct 17 '13 at 09:14
  • Yep, and that's reasonably straightforward, but I still want the reminder behaviour, in case the first email goes unnoticed or gets ignored. – Aaron Sokoloski Oct 17 '13 at 09:25
  • Just guessing: maybe another crontab removing this temp file on a smaller period? – fedorqui Oct 17 '13 at 09:49

0 Answers0