Cron job that needs to run at kind of an odd interval
So I know that if I need something to run every 15 minutes I would use:
Code:
0,15,30,45 * * * * /my/command Would I use: Code:
0,108,216,324 * * * * /my/command To be extra clear, it needs to be 1.8 hours after each job completes. So it couldn't be something like: Code:
10 * * 1 * /my/command |
Out of curiousity, I just stared at the man page for as long as I could stand it.....It **implies** that the fields are what you would expect with something like the date command---ie the minutes field only goes to 59 or 60.
I don't see a solution other than trying it. Set up a simple test and let it run overnight. I would first try: */108 * * * * |
I doubt an interval in minutes that is not a divisor of 60 works as expected. Anyway, it is worth to try and find out.
Another solution is a bit more tricky and it requires a check at the beginning of the script. First we consider at which time the script should run: suppose it starts at midnight of a certain day, then by adding 1h and 48m progressively we get: Code:
0:00 1:48 3:36 5:24 7:12 9:00 10:48 12:36 14:24 16:12 Code:
0,12,24,36,48 * * * * /my/command To do this we have to define a reference date as the date of the first day at midnight at which we want to start our count of three-days periods. Let it be for example midnight of 8-May-2010. All the calculations are processed in seconds and... here we go: Code:
#!/bin/bash Note that all the dates computed by the date command are in UTC time. This should avoid problems in calculations at the passage from and to Daylight Saving Time. Anyway, I'm not sure if this passage will generate some other problems (further testing needed). Hope this helps. |
Very nice solution fellas.
|
All times are GMT -5. The time now is 12:46 AM. |