deeejay

Bash - cron for 1st weekday of month

Dec 22nd, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.74 KB | None | 0 0
  1. Source: http://www.switchplane.com/blog/how-to-run-a-cron-job-on-the-first-weekday-of-the-month/
  2.  
  3. This will run your job at 10am on the first weekday of the month:
  4.  
  5. #-- First weekday of the month
  6.  
  7. # If it's Monday, and it's the 1st, 2nd or 3rd day of the month
  8. # Monday can be 2nd or 3rd day of month following a weekend
  9. 00 10 1-3 * * [ "$(date '+\%a')" == "Mon" ] && /path/to/your/job.sh
  10.  
  11. # If it's Tues - Friday, and the 1st of the month
  12. 00 10 1 * * [ "$(date '+\%a')" == "Tue" ] && /path/to/your/job.sh
  13. 00 10 1 * * [ "$(date '+\%a')" == "Wed" ] && /path/to/your/job.sh
  14. 00 10 1 * * [ "$(date '+\%a')" == "Thu" ] && /path/to/your/job.sh
  15. 00 10 1 * * [ "$(date '+\%a')" == "Fri" ] && /path/to/your/job.sh
  16.  
  17. #-- End first weekday of the month
Advertisement
Add Comment
Please, Sign In to add comment