User Tools

Site Tools


ubuntu:cron:schedule_a_cron_job_to_run_on_the_first_sunday_of_each_month

Ubuntu - Cron - Schedule a Cron Job to Run on the First Sunday of Each Month

It's not possible to schedule a job that will run on the first Sunday of every month using the crontab time-period values.

However, we can leverage the conditional section of the command portion to achieve this.

Notice how the below command is implemented carefully.

0 2 * * sun [ $(date +%d) -le 07 ] && /script/script.sh

This entry will only invoke the script.sh file on the first Sunday of every month.

It is analogous to the command shown below.

0 2 * * 7 [ $(date +%d) -le 07 ] && /script/script.sh
ubuntu/cron/schedule_a_cron_job_to_run_on_the_first_sunday_of_each_month.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki