configure crontab for every 2 days?
Hello,
I need to configure a crontab every 2 days, but only obtain every 2nd day of the week/month Has anyone an idea? Thanks and happy new year to everyone |
I would run in every day and create a filter to skip every second day or whatever you want.
You can use the command date (see format flags) to get day of week, day of month or anything you need. |
Quote:
Your subject line is "configure crontab for every 2 days"...your question then asks to run it every 2nd day of the week/month. That describes THREE different scenarios, either:
|
Periodic crontab entry
Some versions of crontab allow you to put something like */2 or */3 to have the action taken ever two or three (in these examples) of whatever unit you are selecting. If you wanted to run "hello.sh" every 5 minutes, you could have a line in crontab like
*/12 * * * * hello.sh or alternately 0,5,10,15,20,25,30,35,40,45,50,55 * * * * hello.sh |
Periodic cron job
To amplify on what eager said, the third field is "day of month". You could put */2 in that field, knowing that on a transition from a 31-day (or 29-day) month to the next, you won't get an execution until the third day (the 2nd of the next month) after the 30th.
Unfortunately, you can't use any value higher than 23 in the "hour of day" (the second) field, so that won't help you. If it were me, I'd live with the three-day gap at the end of certain months just to make it easier on myself. If I were interested in getting a tiny bit more complex and executing every second day, no matter which month transition is pending, I'd write a script that takes the Julian day of year, modulos it by two, and executes the job when the result is one. Execute that script at a fixed time of day every day in your crontab. The only irregularity you'll have to deal with is at end of year, when your job will run on subsequent days (except leap years). HTH. |
What jtison said. But if you really want every 2 days even across year boundaries then this will print 0 on even days and 1 on odd days. Add an offset of half a day (43200) to time() if you run it close to midnight and are worried about leap seconds.
Code:
perl -e '$day = int(time()/86400); print $day % 2,"\n"' |
By the moment, I configure by the following:
Code:
50 7 */2 * * [execution file] Quote:
|
Quote:
Quoting the man section referred to: Quote:
|
All times are GMT -5. The time now is 04:57 AM. |