Cronjob - Monthly on Saturday
Been reading examples and been searching this forum, but nowhere is stated how to run a cronjob on a specific day of the week - monthly!
I want to run the script every 1st saturday of the month at 7.30am. I tried this one: 30 7 1-7 * 6 Which would bound the script only to send it on the dates 1-7 of the month (I thought), but today 16th, the script was sending my mails... Another option I can think of would be: 30 7 * */1 6 or a combination 30 7 1-7 */1 6 Where */1 would mean once per month (right?!) but not sure or that would work... Any Cron Guru out there?! :) |
Quote:
Your problem may be solved by adding a check at the beginning of your script (if any) or wrap the command you want to run in a script. For example Code:
#!/bin/bash Code:
30 7 * * * /path/to/script.sh Edit: take in mind that crontab fields are addictive, that is if you specify Code:
30 7 1-7 * 6 |
Quote:
I went wrong with NOT knowing that crons are addictive. So I will go for the in-script solution and just run the script every saturday. eg. (PHP script) Code:
// Once a month, otherwise exit script Code:
30 7 * * 6 |
How do you run cron every 2 saturdays...
I would like add a cron for running a job every 2 saturdays .....
How do you do that? |
Hi babinu and welcome to LinuxQuestions!
Quote:
Said that, you can simply run your job every Saturday: Code:
30 9 * * 6 /path/to/script.sh Code:
if [ $(($(date +%W) % 2)) -eq 1 ] A downside is on year changes. Last week is 53 and first week of the new year is odd as well, so that your job will run two consecutive weeks. To avoid that you can: 1. Add a more fined control on even or odd years and switch to even or odds weeks accordingly. 2. Use a totally different approach and create/delete a dummy file every time the script runs. It will check for the presence of the file and a) if the file is absent don't run and create it, b) if the file is present run and delete it. In other words you can use a file as a toggle (for example you can create/delete a hidden file in your home directory with a unique name). Edit: I checked and on my system the last week of the year is 52, whereas the first week is 00. Anyway, this does not change the considerations above. |
All times are GMT -5. The time now is 05:10 PM. |