Re: Cron, > 1 month but < 2 months
>> On Sun, 11 Mar 2012 01:42:25 -0600, Christofer C. Bell wrote:
C> According to this page[1], the following works for that:
C> * * */45 * * your_scheduled_task
C> I've not tried it myself.
I'd use a timestamp file in conjunction with find; what happens when
your 45-day interval crosses Jan 1st? For example:
me% date
Sun Mar 11 21:51:21 EDT 2012
me% touch -d '45 days ago' timestamp
me% ls -l --time-style='+%d-%b-%Y %T' timestamp
-rw-r--r-- 1 me me 0 26-Jan-2012 20:51:27 timestamp
me% find timestamp -daystart -mtime +1 -print
timestamp
me% find timestamp -daystart -mtime +44 -print
timestamp
me% find timestamp -daystart -mtime +45 -print # no output
Run something like this every day:
#!/bin/bash
ts=/time/stamp/file
interval=45
set X $(find $ts -daystart -mtime +$interval -print)
shift
case "$#" in
0) logger 'starting' ;;
*) logger 'skipping'; exit 0 ;;
esac
# run your php script or whatever ...
touch $ts
Another advantage: you can decide whether to "touch $ts" based on the
return code from whatever you're trying to run. If it fails, do you
want to alert someone and run it tomorrow or wait another 45 days?
Reschedule by setting the $ts modtime instead of dorking around with cron.
--
Karl Vogel I don't speak for the USAF or my company
Bumper-sticker on Mel Gibson's car: "Swerve If You Love Jesus"
Reply to: