Cron job first Sunday of the month
Solved
splintermik
-
splintermik -
splintermik -
Hello everyone, here it is, I would like a command to execute every 1st Sunday of each month
So I put this in crontab -e
01 00 1-7 * 0 command
The problem is that the command runs every Sunday and every day from the 1st to the 7th
Is there another command that would allow it to run once, for the 1st Sunday of each month?
Thank you
So I put this in crontab -e
01 00 1-7 * 0 command
The problem is that the command runs every Sunday and every day from the 1st to the 7th
Is there another command that would allow it to run once, for the 1st Sunday of each month?
Thank you
3 answers
-
Hello,
An interesting solution:
https://stackoverflow.com/questions/3241086/how-to-schedule-to-run-first-sunday-of-every-month
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script
"The date +%d gives you the number of the current day and then you can check if the day is less than or equal to 7. If it is, then run your command.
If you run this script only on Sundays, it should mean that it runs only on the first Sunday of the month." -
Another solution, a bit less clean (even messy):
You initialize a file 'premierdimanche' to 0.
You run your script every Sunday and check the content of this file:
• if it is 0: you run the script content and set the file content to 1.
• if it is 1: your script has already been run this month.
Then, you add a task on the 1st of the month to reset this file to 0. -
Hi,
It's impossible to directly set the first Sunday of the month in the crontab settings.
However, it's possible to work around it, as explained here.
--
☯ Zen my nuggets ☮
Do something for the environment, close your windows and adopt a penguin. <('')-
Thank you for your response
I just tested with at, so here is the command
at now +1 minutes /etc/blablabla
I got back
syntax error. Last token seen: /
Garbled time
So I tried: at now +1 minutes etc/blablabla
and I got:
syntax error. Last token seen: e
Garbled time
I don't really understand how this works, if it's a command that can only be executed via the console, it isn't very useful for running automatically every first Sunday of the month :p
-