Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monit for "cron-like" tasks

Tags:

monit

Have some batch-type jobs that I would like to move from cron to Monit but am struggling to get them to work properly. These scripts typically run once a day, but on occasion have to be re-ran later in the day. Goal is to take advantage of the monit & m/monit front-ends to re-run as well as be alerted on failure in similar fashion to other things under monit.

The below was my first attempt. I know the docs say to use range/wildcard for minute field but I have my monit daemon set to cycle every 20 seconds so thought I'd be able to get away with this.

check program test.sh
    with path "/usr/local/bin/test.sh"
    every "0 7 * * *"
    if status != 0 then alert

This does not seem to work as it seems like it picks up the exit status of the program on the NEXT run. So I have a zombie process sitting around until 7am the next day, at which time I'll see the status from the previous day's run.

Would be nice if this ran immediate or if there was a way to schedule something as "batch" that would only run once when started (either from command line or web gui). Example below.

check program test.sh
    with path "/usr/local/bin/test.sh"
    mode batch
    if status != 0 then alert

Is it possible to do what I want? Can a 'check program' be scheduled that will only run one time when started or using the 'every [cron]' type syntax supported by monit?

TIA for any suggestions.

like image 460
mr19 Avatar asked Mar 18 '26 08:03

mr19


1 Answers

The latest version of monit (5.18) now picks up the exit status on the next daemon cycle, not on the next execution of the program like in the past (which might not be until the next day).

like image 190
mr19 Avatar answered Mar 20 '26 04:03

mr19



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!