Reputation: 3181
I need to invoke my shell script every two days, I read about cron daemon that it can help me invoking scripts periodically, so can you give an example how can I make my script able to be invoked by cron daemon.
Upvotes: 0
Views: 881
Reputation: 3897
There is no way to execute exactly every 48 hours with the classical cron, not even with more than one tab entry.
Every 2 days is an average of 0.5 times per day. However, "1-31/2" as posted by others, runs 0.509851 times per day on average, in other words: approx every 47h 4min over a timeframe of 400 years. (Because it will run on both the 31st of an odd month, and the 1st of the following month.)
Edit: "*/2" would run 179x/year, which is 0.49041, so that is not exact either.
Hooray for the Gregorian calendar.
Upvotes: 1
Reputation: 140377
Invoke crontab -e
to bring up the cron editor
The format for crontab is: MIN HOUR DAY MONTH DAYOFWEEK COMMAND
Therefore to make a script run every 2 days, you'll want:
0 0 */2 * * /path/to/command
Once you're done, type :x
to save and quit. You can then run crontab -l
(that's an ell) to make sure it took hold.
*Note: It's actually a bit ambiguous if your cron daemon will run that every two days on even days (2,4,6..) or odd days (1,3,5..) and it may switch these depending on how many days are in the current month. If you want to unambigufy this, you can do this:
0 0 1-31/2 * * /path/to/command
0 0 0-30/2 * * /path/to/command
Upvotes: 2
Reputation: 47321
0 0 1-31/2 * * your_script
________^ NOT divined, but run every 2 days
the above will run once in two days at 00:00:00am
you can do man 5 crontab
to get some helpful information
Upvotes: 1