Misty wrote regarding 'Re: [SLE] Pullin' my hair out... arrrgh' on Thu, Aug 05 at 10:55:
Sigh... if you run it every 6 hours and have it ask "Is it 18 hours yet?" Every third time, it will be, and it will complete. else, it will exit its cute little loop. Running a script != doing an action.
I do somewhat like the idea of a self-modifying script. Each time it runs, the first thing it does is check its own timestamp and see if that's more than, say 17 hours ago. If it is, it touches itself (touch $0) and goes on, otherwise it exits. Then you can do the '1 */6 * * *' route... Ok, so there's no nice date comparison function other than newer/older in my bash man page. Just make a temporary file (how about using "/tmp/pid-$$" - $$ is the pid and there probably won't be a file with the that name in /tmp), and date that file 17 hours ago. If that file's older than the script, then this script was last run less than 17 hours ago. If that file's not older, then this is the 18th hour run. #!/bin/bash SEVENTEEN_AGO=`date -d '17 hours ago' +%Y%m%d%H%M.%S` TEST_FILE="/tmp/$$" touch -t $SEVENTEEN_AGO "$TEST_FILE" if [ "$TEST_FILE" -ot "$0" ]; then # script was last run 6 or 12 hours ago rm "$TEST_FILE" exit fi rm "$TEST_FILE" touch "$0" # do script stuff here I went with 17 hours to compensate for a little clock drift in between the 6 hour cycles. There you go. One line in crontab, no additional timestamp files that need to be hanging around forever, etc, and little risk of someone tampering with the timestamp file since there's only a few cycles between the stampfile being dated and when it's compared. Also, no problems with at having to run, regenerate, etc. Change '17 hous ago' to '5 seconds ago' if you wanna quickly test it... ;) Have fun. --Danny, pretty pleased with himself ;)