I would like to set up a cron task to run a script every first day of every month except 1st january. How can I do that?
Could I try something like that: 0 0 1 2-12 * ?
Some cron implementations support the "L" flag to represent the last day of the month. If you're lucky to be using one of those implementations, it's as simple as: 0 55 23 L * ? That will run at 11:55 pm on the last day of every month.
Identify Last Day of Month So, first of all, we will schedule cron on the 28,28,29 and 31'st of each month. Now find out if today is the last day of the month. To find it check if the next day is 01'st of the next day and then only execute any command. Below command will return the date of the next day.
You need to combine two approaches: a) Use cron to run a job every Sunday at 9:00am. b) At the beginning of once_a_week , compute the date and extract the day of the month via shell, Python, C/C++, ... and test that is within 1 to 7, inclusive. If so, execute the real script; if not, exit silently.
Cron is a powerful tool in linux-based operating systems to execute jobs at specified intervals. This easy hack makes monthly cron jobs execute at a specific date. The easiest way to execute a script as a scheduled job is to put your script executable file on cron folders: /etc/cron.
It can be something like below:
0 0 1 2,3,4,5,6,7,8,9,10,11,12 *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With