deeejay icon

Bash - cron for 1st weekday of month

deeejay | PRO | 12/23/14 12:10:40 AM UTC | 0 ⭐ | 334 👁️ | Never ⏰ | []
Bash |

740 B

|

None

|

0 👍

/

0 👎

Source: http://www.switchplane.com/blog/how-to-run-a-cron-job-on-the-first-weekday-of-the-month/
 
This will run your job at 10am on the first weekday of the month:
 
#-- First weekday of the month
 
# If it's Monday, and it's the 1st, 2nd or 3rd day of the month
# Monday can be 2nd or 3rd day of month following a weekend
00 10 1-3 * * [ "$(date '+\%a')" == "Mon" ] && /path/to/your/job.sh
 
# If it's Tues - Friday, and the 1st of the month
00 10 1 * * [ "$(date '+\%a')" == "Tue" ] && /path/to/your/job.sh
00 10 1 * * [ "$(date '+\%a')" == "Wed" ] && /path/to/your/job.sh
00 10 1 * * [ "$(date '+\%a')" == "Thu" ] && /path/to/your/job.sh
00 10 1 * * [ "$(date '+\%a')" == "Fri" ] && /path/to/your/job.sh
 
#-- End first weekday of the month

Comments