Recurring execution of a script with cron

I found a reliable way to remind myself of a recurring event that happens every second month at the first saturday of that month.

30  3 1-7 1,3,5,7,9,11 Sat /Users/dominic/tom/bin/

The script runs on month 1,3,5,7,9 and 11 if it’s a saturday and between day 1-7.

This works quite good—but today I use another configuration.

30  3 * 1,3,5,7,9,11 6  /Users/dominic/tom/bin/

This version runs on every Saturday (6) on month 1,3,5,7,9,11; the script itself checks if it’s the first saturday or not.

That way I get a notification on every execution (every saturday in above mentioned months) and the report shows me more details. The report also contains the information if the actual function got executed or not—it’s easier to tell, if the script still runs correctly or not.

# get the actual day in numbers form
TODAY="`date +%_d`"

# check if its the first saturday (the first saturday must be one of day 1-7)
if [ $TODAY -gt "7" ]; then
  # that means, $TODAY is greater than 7. Send a negative report and quit the script.
  # set a variable or silently quit the program
  #return 0
  # execute the final action/function
  # set special variables etc.
# you can now decide what to do. read content of $ACTION and execute the correct functions here
# depending on the valued of $ACTION that we have set in our if-clause above. Or just quite the
# script silently in the proper branch of that if-clause.

Hopefully this information was quite understandable. I’m not a good english writer and this article was quite hard to write. I might not have found the correct words every time so please feel free to comment and improve that content.

Comments won't work at the moment

I'm sorry but the comments are offline. I'm not sure when I have fixed this issue, but I'll let you know when comments are back online.

Explore more:


↑ back to top