Shell – Cron to not run on specific day but all other days

cronshell-script

I have a cron setup to execute a bash script daily at 10pm. I have another cron setup to run monthly on the 1st of the month. Both crons launch a bash script, and the only different in the bash script is the argument they pass into the underlying java program (emulating command line launch of the java program).

The problem is, I need to somehow disable the daily cron on the 1st of the month so that both don't try to run on the same day. Is this possible to do automatically?

I suppose I can create another bash script to edit the cron before the 1st then again after to set things back up, but this seems… unclean.

Best Answer

In a similar vein to the solution proposed by @StephaneChazelas in the comments you could specify the range of days in the 3rd field as a range for the cron that you want to run on every day besides the 1st of the month.

The following two entries would accomplish what you're after:

   0 22 1 * *      /path/to/script/1st_of_the_month.bash    
   0 22 2-31 * *   /path/to/script/every_day_except_1st.bash
Related Question