I have been trying to use the cron package for scheduled bash script execution as is generally intended, and have found almost everything I need via this resource here

However the part I was unable to find, was the means for which I can set a beginning and end for a particular cron schedule to be conditional, ie I suppose I wanted a particular cron job to only be executed in march daily, and to then continue in april if say some binary variable (whose value is determined from some sort of assessment of the cron job's march output) is 1, and for the the cron job to be terminated until further notice if it's value is 0.

I apologise if my phrasing is unclear, constructive criticism is appreciated.

  • Where is this variable supposed to reside? – glenn jackman Feb 26 at 18:39
  • ok well what I had envisaged, which obviously hypothetical, I'm very new to things, was a separate cron schedule to perform the "evaluation" of the original cron job, and pipe the output to the "cron job continuity variable" – Adam Feb 26 at 18:42
  • so I suppose it would need to be an environmental variable I would need to create which again is another learning process I'm in the middle of – Adam Feb 26 at 18:44
  • @user535733 is this the kind of thing you are refering to? tldp.org/LDP/abs/html/testconstructs.html – Adam Feb 26 at 18:53
  • 1
    You could arrange for the March cronjob to create (or delete) a file, and for the April cronjob to test for the file's presence (or absence) using text -f /path/to/runfile && rest-of-your-cronjob - kind of like how /forcefsck used to be used on reboot – steeldriver Feb 26 at 18:57

You can put variables in the crontab file, so you can have


Then implement the condition with this /bin/sh construct

* * * * * [ "$EXECUTE_JOB" = "1" ] && your existing job here

Then, on April 1, you can adjust the value of that variable accordingly

  • ok thankyou for this – Adam Feb 26 at 18:45

Your Answer

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

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