0

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.

7
  • Where is this variable supposed to reside? Commented Feb 26, 2019 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" Commented Feb 26, 2019 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 Commented Feb 26, 2019 at 18:44
  • @user535733 is this the kind of thing you are refering to? tldp.org/LDP/abs/html/testconstructs.html Commented Feb 26, 2019 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 Commented Feb 26, 2019 at 18:57

1 Answer 1

3

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

EXECUTE_JOB=1

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .