I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose. Is there a cleaner way of doing this? Thanks! -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
C Hamel wrote:
I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose.
Is there a cleaner way of doing this?
Thanks!
I suppose you could have it run every hour and decrement a counter from 18 and execute the main part of the script, when it hits 0, and then reset the counter.
On Wednesday 04 August 2004 19:22, C Hamel wrote:
I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose.
Is there a cleaner way of doing this?
finish the script with something like cat << EOF |at now + 18 hours /usr/bin/scriptname EOF
Anders wrote regarding 'Re: [SLE] Pullin' my hair out... arrrgh' on Wed, Aug 04 at 12:50:
On Wednesday 04 August 2004 19:22, C Hamel wrote:
I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose.
Is there a cleaner way of doing this?
finish the script with something like
cat << EOF |at now + 18 hours /usr/bin/scriptname EOF
I'm partial to echo $0 | at now + 18 hours since it continues to work even if the script gets moved/renamed and I forget to change self references inside the script. Data duplication is bad. ;) This is assuming the use of a shell that puts the command in $0, obviously. It might be a good idea to touch a file (/var/state/scriptname, perhaps) to ensure that the script's running periodically, and have a cron job that sends a warning email if that file's older than 18 hours or so... --Danny, who also dislikes here documents, in general
Danny, On Wednesday 04 August 2004 11:15, Danny Sauer wrote:
Anders wrote regarding 'Re: [SLE] Pullin' my hair out... arrrgh' on Wed, Aug 04 at 12:50:
...
Is there a cleaner way of doing this?
finish the script with something like
cat << EOF |at now + 18 hours /usr/bin/scriptname EOF
I'm partial to
echo $0 | at now + 18 hours
You probably want this: echo "$@" |at now + 18 hours The quotes are always advisable and should there be any arguments, presumably you'd want them passed on as well.
since it continues to work even if the script gets moved/renamed and I forget to change self references inside the script. Data duplication is bad. ;) This is assuming the use of a shell that puts the command in $0, obviously.
It might be a good idea to touch a file (/var/state/scriptname, perhaps) to ensure that the script's running periodically, and have a cron job that sends a warning email if that file's older than 18 hours or so...
--Danny, who also dislikes here documents, in general
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary. Randall Schulz
On Wednesday 04 Aug 2004 19:33 pm, Randall R Schulz wrote:
Danny,
On Wednesday 04 August 2004 11:15, Danny Sauer wrote: <SNIP>
--Danny, who also dislikes here documents, in general
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary.
What are 'here documents'? Dylan -- "I see your Schwartz is as big as mine" -Dark Helmet
On Wednesday 04 August 2004 20:43, Dylan wrote:
On Wednesday 04 Aug 2004 19:33 pm, Randall R Schulz wrote:
Danny,
On Wednesday 04 August 2004 11:15, Danny Sauer wrote:
<SNIP>
--Danny, who also dislikes here documents, in general
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary.
What are 'here documents'?
The format I used in my mail. Insanely useful. Basically, you do $command << SOMETHING line1 line2 SOMETHING and $command will use the lines between the first line and the line with SOMETHING as standard input. Those lines are called a here document. It's described in "man bash". Extremely useful if you have multi-line commands for something and don't want to litter your script with a thousand "echo"s or end each line with a \
Anders, On Wednesday 04 August 2004 11:50, Anders Johansson wrote:
On Wednesday 04 August 2004 20:43, Dylan wrote:
On Wednesday 04 Aug 2004 19:33 pm, Randall R Schulz wrote:
...
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary.
What are 'here documents'?
The format I used in my mail. Insanely useful. ...
Useful? Definitely. Insane? Perhaps. Insanely useful? Perhaps only to the insane... Anyway, one of my favorite uses of here documents are for setting PATH and PATH-like variables (PATH, CDPATH, CLASSPATH, etc.): export PATH=`tr $'\n' ":" <<-endPATH . $HOME/bin /usr/local/bin /opt/cxoffice/bin /sbin /usr/sbin /bin /usr/bin /usr/X11R6/bin /opt/kde3/bin /opt/gnome/bin endPATH` # Strip the trailing colon produced by the unavoidable # newline at the end of the here document PATH="${PATH%:}" Randall Schulz
On Wednesday 04 August 2004 20:57, Randall R Schulz wrote:
Useful? Definitely. Insane? Perhaps. Insanely useful? Perhaps only to the insane...
I'm insane, yes, but hold that thought
Anyway, one of my favorite uses of here documents are for setting PATH and PATH-like variables (PATH, CDPATH, CLASSPATH, etc.):
export PATH=`tr $'\n' ":" <<-endPATH .
Dot in your $PATH, and *first*? You must find here documents insanely useful too Anyway, nice trick to use
Randall wrote regarding 'Re: [SLE] Pullin' my hair out... arrrgh' on Wed, Aug 04 at 13:33:
Danny,
On Wednesday 04 August 2004 11:15, Danny Sauer wrote:
Anders wrote regarding 'Re: [SLE] Pullin' my hair out... arrrgh' on Wed, Aug 04 at 12:50:
...
Is there a cleaner way of doing this?
finish the script with something like
cat << EOF |at now + 18 hours /usr/bin/scriptname EOF
I'm partial to
echo $0 | at now + 18 hours
You probably want this:
echo "$@" |at now + 18 hours
The quotes are always advisable and should there be any arguments, presumably you'd want them passed on as well.
Doh! Yes, quotes should be there, in case the programs's named '-n' or something bizarre like that. We're both wrong, though. I meant echo "$0 $@" | at now + 18 hours $0 is the command $@ is the args both are needed - though my $0 would've worked better alone than your $@... :)
--Danny, who also dislikes here documents, in general
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary.
When they're cool, I like them too. In general, they're not cool, though, since I use perl more than shells for scripting, and it's easier to just leave a pair of quotes open for multi-line strings in most cases. ;) --Danny
Danny, On Wednesday 04 August 2004 13:22, Danny Sauer wrote:
...
I'm partial to
echo $0 | at now + 18 hours
You probably want this:
echo "$@" |at now + 18 hours
The quotes are always advisable and should there be any arguments, presumably you'd want them passed on as well.
Doh! Yes, quotes should be there, in case the programs's named '-n' or something bizarre like that. We're both wrong, though. I meant
echo "$0 $@" | at now + 18 hours
$0 is the command $@ is the args both are needed - though my $0 would've worked better alone than your $@... :)
Yup. One good SNAFU deserves another... Since programming is a practice well served by the persnickety, I'll make one final revision: echo "$0" "$@" |at now + 18 hours
--Danny, who also dislikes here documents, in general
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary.
When they're cool, I like them too. In general, they're not cool, though, since I use perl more than shells for scripting, and it's easier to just leave a pair of quotes open for multi-line strings in most cases. ;)
I'm not sure about all shells, but BASH allows multi-line, unescaped strings on the command line and in scripts. I also find BASH's $'C-style escape codes expanded in this kind of string' feature very handy. It's described in the "QUOTING" section of the BASH manual page.
--Danny
Randall Schulz
Yup. One good SNAFU deserves another...
Since programming is a practice well served by the persnickety, I'll make one final revision:
echo "$0" "$@" |at now + 18 hours
--Danny, who also dislikes here documents, in general
Here documents are cool, but they make scripts harder to read and understand, so I avoid using them unless they're really necessary.
When they're cool, I like them too. In general, they're not cool, though, since I use perl more than shells for scripting, and it's easier to just leave a pair of quotes open for multi-line strings in most cases. ;)
I'm not sure about all shells, but BASH allows multi-line, unescaped strings on the command line and in scripts. I also find BASH's $'C-style escape codes expanded in this kind of string' feature very handy. It's described in the "QUOTING" section of the BASH manual page.
--Danny
Randall Schulz I was wondering about using cron, but thought that it was limited to the time
On Wednesday 04 August 2004 15:41, Randall R Schulz wrote: <SNIP> frames within kcron, since I had trouble trying something even more simple w/ vcron (as in, something more simple wouldn't execute). If I put it directly in crontab, wouldn't the [* /1080 * * *] work? Perhaps I should just do the task manually (if I don't forget) if it is that complicated...? -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
I'm partial to
echo $0 | at now + 18 hours
since it continues to work even if the script gets moved/renamed and I forget to change self references inside the script. Data duplication is bad. ;) This is assuming the use of a shell that puts the command in $0, obviously.
It might be a good idea to touch a file (/var/state/scriptname, perhaps) to ensure that the script's running periodically, and have a cron job that sends a warning email if that file's older than 18 hours or so...
--Danny, who also dislikes here documents, in general Interesting. I don't think the command format you used is specified in the man pages. If it is, I missed it ...and I read it all. -- ...CH "The more they over-think the plumbing,
On Wednesday 04 August 2004 13:15, Danny Sauer wrote: <SNIP> the easier it is to stop up the drain." Scotty
How about the following in crontab * */18 * * * someuser /usr/local/bin/script > /dev/null This should execute 'script' every 18 hours as user someuser On Wed, 4 Aug 2004 12:22:04 -0500, C Hamel wrote
I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose.
Is there a cleaner way of doing this?
Thanks! -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
On Wednesday 04 August 2004 19:50, Doug Currey wrote:
How about the following in crontab
* */18 * * * someuser /usr/local/bin/script > /dev/null
This should execute 'script' every 18 hours as user someuser
No, that will execute it 60 times between midnight and 1am, and 60 times between 6pm and 7pm each day
On Wed, 4 Aug 2004 20:04:45 +0200, Anders Johansson wrote
On Wednesday 04 August 2004 19:50, Doug Currey wrote:
How about the following in crontab
* */18 * * * someuser /usr/local/bin/script > /dev/null
This should execute 'script' every 18 hours as user someuser
No, that will execute it 60 times between midnight and 1am, and 60 times between 6pm and 7pm each day
Are you sure about that?
From the crontab(5)
Step values can be used in conjunction with ranges. Following a range with `/' specifies skips of the number's value through the range. For example, `0-23/2' can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is `0,2,4,6,8,10,12,14,16,18,20,22'). Steps are also permitted after an asterisk, so if you want to say `every two hours', just use `*/2'.
On Wednesday 04 August 2004 20:19, Doug Currey wrote:
On Wed, 4 Aug 2004 20:04:45 +0200, Anders Johansson wrote
On Wednesday 04 August 2004 19:50, Doug Currey wrote:
How about the following in crontab
* */18 * * * someuser /usr/local/bin/script > /dev/null
This should execute 'script' every 18 hours as user someuser
No, that will execute it 60 times between midnight and 1am, and 60 times between 6pm and 7pm each day
Are you sure about that?
Yes
From the crontab(5)
Step values can be used in conjunction with ranges. Following a range with `/' specifies skips of the number's value through the range. For example, `0-23/2' can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is `0,2,4,6,8,10,12,14,16,18,20,22'). Steps are also permitted after an asterisk, so if you want to say `every two hours', just use `*/2'.
Indeed, so */18 is the same as stepping from 0 to 23 with a step of 18. In other words, */18 is equivalent to 0,18. The actual code in cron is for (i = num1; i <= num2; i += num3) if (EOF == set_element(bits, low, high, i)) return EOF; In this case, num1 is 0, num2 is 23 and num3 is 18 Also note the "60 times" remark. You had * for the minute field, which means it will execute once per minute every minute in the hour given
On Wednesday 04 August 2004 13:24, Anders Johansson wrote:
On Wednesday 04 August 2004 20:19, Doug Currey wrote:
On Wed, 4 Aug 2004 20:04:45 +0200, Anders Johansson wrote
On Wednesday 04 August 2004 19:50, Doug Currey wrote:
How about the following in crontab
* */18 * * * someuser /usr/local/bin/script > /dev/null
This should execute 'script' every 18 hours as user someuser
No, that will execute it 60 times between midnight and 1am, and 60 times between 6pm and 7pm each day
Are you sure about that?
Yes
From the crontab(5)
Step values can be used in conjunction with ranges. Following a range with `/' specifies skips of the number's value through the range. For example, `0-23/2' can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is `0,2,4,6,8,10,12,14,16,18,20,22'). Steps are also permitted after an asterisk, so if you want to say `every two hours', just use `*/2'.
Indeed, so */18 is the same as stepping from 0 to 23 with a step of 18. In other words, */18 is equivalent to 0,18. The actual code in cron is
for (i = num1; i <= num2; i += num3) if (EOF == set_element(bits, low, high, i)) return EOF;
In this case, num1 is 0, num2 is 23 and num3 is 18
Also note the "60 times" remark. You had * for the minute field, which means it will execute once per minute every minute in the hour given Okay... as I understand it, I'd use the following:
* /18 * * * ...to execute every 18th hour. That's what I put in there. -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
On Wednesday 04 August 2004 08:47 am, Anders Johansson wrote:
On Wednesday 04 August 2004 20:40, C Hamel wrote:
Okay... as I understand it, I'd use the following:
* /18 * * * ...to execute every 18th hour. That's what I put in there.
I give up
Don't give up. I understood you. Jerome
* Jerome Lyles
On Wednesday 04 August 2004 08:47 am, Anders Johansson wrote:
I give up
Don't give up. I understood you.
So *will* C Hamel, eventually, expecially if he has set 'mailto:'. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Photo Album: http://wahoo.no-ip.org/photos
* Jerome Lyles
[08-04-04 16:19]: On Wednesday 04 August 2004 08:47 am, Anders Johansson wrote:
I give up
Don't give up. I understood you.
So *will* C Hamel, eventually, expecially if he has set 'mailto:'. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Photo Album: http://wahoo.no-ip.org/photos Uh-oh... *that* sounds ominous... :-\ <G> -- ...CH "The more they over-think the plumbing,
On Wednesday 04 August 2004 16:57, Patrick Shanahan wrote: the easier it is to stop up the drain." Scotty
Op donderdag 5 augustus 2004 02:35, schreef C Hamel:
On Wednesday 04 August 2004 16:57, Patrick Shanahan wrote:
* Jerome Lyles
[08-04-04 16:19]: On Wednesday 04 August 2004 08:47 am, Anders Johansson wrote:
I give up
Don't give up. I understood you.
So *will* C Hamel, eventually, expecially if he has set 'mailto:'. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Photo Album: http://wahoo.no-ip.org/photos
Uh-oh... *that* sounds ominous... :-\ <G> -- ...CH When I read Patrick's comment I immediately thought "either that or he loses all his hair". It seems you've been lucky this time.
Best regards, -- Jos van Kan
Indeed, so */18 is the same as stepping from 0 to 23 with a step of 18. In other words, */18 is equivalent to 0,18. The actual code in cron is
for (i = num1; i <= num2; i += num3) if (EOF == set_element(bits, low, high, i)) return EOF;
In this case, num1 is 0, num2 is 23 and num3 is 18
Also note the "60 times" remark. You had * for the minute field, which means it will execute once per minute every minute in the hour given
Ok I see now!
Indeed, so */18 is the same as stepping from 0 to 23 with a step of 18. In other words, */18 is equivalent to 0,18. The actual code in cron is
for (i = num1; i <= num2; i += num3) if (EOF == set_element(bits, low, high, i)) return EOF;
In this case, num1 is 0, num2 is 23 and num3 is 18
Also note the "60 times" remark. You had * for the minute field, which means it will execute once per minute every minute in the hour given
Ok I see now! Well... I actually had it set as follows: 58 /18 * * * ...then someone e-mailed me privately stating that he thought it ought to be: 58 /1080 * * * ....so I guess I'll see what takes place when the time comes. In my example, [* /18 * * *] I was concentrating on the hour, rather than the minute, but did set the minute in the crontab. -- ...CH "The more they over-think the plumbing,
On Wednesday 04 August 2004 17:42, Doug Currey wrote: the easier it is to stop up the drain." Scotty
On Thursday 05 August 2004 02:39, C Hamel wrote:
Well... I actually had it set as follows: 58 /18 * * * ...then someone e-mailed me privately stating that he thought it ought to be: 58 /1080 * * *
Congratulations. Since you're obviously not listening to me you won't be able to hear me laughing. I'd be interested to know if this anonymous someone really thinks that would work, or if he was just making fun of you
....so I guess I'll see what takes place when the time comes.
Happy waiting. That line will *never* run
On Wednesday 04 August 2004 19:58, Anders Johansson wrote: <SNIP>
Congratulations. Since you're obviously not listening to me you won't be able to hear me laughing.
I'd be interested to know if this anonymous someone really thinks that would work, or if he was just making fun of you
....so I guess I'll see what takes place when the time comes.
Happy waiting. That line will *never* run This is the actual line for crontab, plus the explanation. Do you disagree?
0 /1080 * * * * <script> 2&>1 /dev/null should be equal to every 1080 minutes which divided 60 gives you 18. -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
On Thursday 05 August 2004 03:33, C Hamel wrote:
This is the actual line for crontab, plus the explanation. Do you disagree?
With every fibre in my body
0 /1080 * * * * <script> 2&>1 /dev/null should be equal to every 1080 minutes which divided 60 gives you 18.
0 is not a range. And the minutes of an hour only goes from 0 to 59. This is simply not the way crontab works. The minute field holds the minute(s) of the hour when you want to run the script. It can be a range, such as 10-20 or 0-59 or *, and a range can have a step value, such as 10-20/2, which means "from 10 to 20, every two minutes". But this "every two minutes" does not mean what you think it does. Specifically, it does not mean that you can "cross the line" into the next hour, with that 1080 you have. What your line would do (provided there isn't a space between 0 and /, as there appears to be) is the same as if you had put 0 * * * *, since cron will add 1080, observe that 1080 is greater than 59, and stop. It is just not possible to do what you want with a simple one-line solution in crontab. Also, the last bit should probably be <script> > /dev/null 2>&1
-- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
On Wednesday 04 August 2004 21:29, Anders Johansson wrote:
On Thursday 05 August 2004 03:33, C Hamel wrote:
This is the actual line for crontab, plus the explanation. Do you disagree?
With every fibre in my body
0 /1080 * * * * <script> 2&>1 /dev/null should be equal to every 1080 minutes which divided 60 gives you 18.
0 is not a range. And the minutes of an hour only goes from 0 to 59. This is simply not the way crontab works. The minute field holds the minute(s) of the hour when you want to run the script. It can be a range, such as 10-20 or 0-59 or *, and a range can have a step value, such as 10-20/2, which means "from 10 to 20, every two minutes". But this "every two minutes" does not mean what you think it does. Specifically, it does not mean that you can "cross the line" into the next hour, with that 1080 you have. What your line would do (provided there isn't a space between 0 and /, as there appears to be) is the same as if you had put 0 * * * *, since cron will add 1080, observe that 1080 is greater than 59, and stop.
It is just not possible to do what you want with a simple one-line solution in crontab.
Also, the last bit should probably be
<script> > /dev/null 2>&1
Got it. Thanks for the 'dummy's explanation' :-) -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
On Wednesday 04 August 2004 13:04, Anders Johansson wrote:
On Wednesday 04 August 2004 19:50, Doug Currey wrote:
How about the following in crontab
* */18 * * * someuser /usr/local/bin/script > /dev/null
This should execute 'script' every 18 hours as user someuser
No, that will execute it 60 times between midnight and 1am, and 60 times between 6pm and 7pm each day What would you recommend? I'd prefer using cron, if I can.... but if not will have to use 'at' ...though it seems limited by the fact that one cannot specify an 'every 18 hours' time-frame.
Just when I thought I understood. :-\ <LOL> Like Basil Chupin stated: "I'm not young enough to know everything." -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
On Wednesday 04 August 2004 20:19, C Hamel wrote:
On Wednesday 04 August 2004 13:04, Anders Johansson wrote:
On Wednesday 04 August 2004 19:50, Doug Currey wrote:
How about the following in crontab
* */18 * * * someuser /usr/local/bin/script > /dev/null
This should execute 'script' every 18 hours as user someuser
No, that will execute it 60 times between midnight and 1am, and 60 times between 6pm and 7pm each day
What would you recommend?
See my other mail for my recommendation
I'd prefer using cron, if I can.... but if not will have to use 'at' ...though it seems limited by the fact that one cannot specify an 'every 18 hours' time-frame.
Using cron I think you would have to set up several lines. with 18 hour steps, you get a three day cycle, it should be possible to work something out using a couple of lines in crontab. the at method is simpler though
Just when I thought I understood. :-\ <LOL> Like Basil Chupin stated: "I'm not young enough to know everything."
Basil Chupin is Oscar Wilde????
On Wednesday 04 August 2004 13:30, Anders Johansson wrote: <SNIP >
Basil Chupin is Oscar Wilde????
OOOOPS! Correction! He put that saying below the sig line in his e-mails, for awhile. I didn't mean he originated it. sorry -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
* Anders Johansson
the at method is simpler though
Just don;t forget to turn on the atd
chkconfig atd on
It's off on a default suse 9 install .
Currently listening to: wp1997-07-22d1t08
Gerhard,
* C Hamel
I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose.
man at -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Photo Album: http://wahoo.no-ip.org/photos
Many thanks for all the suggestions. My mind was turning to clay because there are still things I don't know about Linux. ;-) Think I have a handle on it, now! -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
C Hamel wrote:
Many thanks for all the suggestions. My mind was turning to clay because there are still things I don't know about Linux. ;-) Think I have a handle on it, now!
So, how did you solve it. With some invaluable help, yes! -- ...CH "The more they over-think the plumbing,
On Wednesday 04 August 2004 14:00, James Knott wrote: the easier it is to stop up the drain." Scotty
Every 18 hours huh? 18 is a multiple of 6. 6*3 is 18, 6*4 is 24. Every 18 hours would be 6, 24, 18, 12. Run the cron job at all of these times, have it check for a file /tmp/should_run that gets generated when the script should run. On Wednesday 04 August 2004 12:22, C Hamel wrote:
I need a script to execute every 18 hours w/o having to change the crontab daily, if possible. I have tried sleeping/recalling script but, of course, one has to then kill a bunch of pids for older executions of the same script ...but at least not daily, I don't suppose.
Is there a cleaner way of doing this?
Thanks! -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
-----Original Message-----
From: Misty Stanley-Jones
Every 18 hours huh? 18 is a multiple of 6. 6*3 is 18, 6*4 is 24. Every 18 hours would be 6, 24, 18, 12. Run the cron job at all of these times, have it check for a file /tmp/should_run that gets generated when the script should run.
Won't work. You need to use an at job for this and have the command resubmit itself to run again in 18 hours. Ken
On Wednesday 04 August 2004 21:00, Misty Stanley-Jones wrote:
Every 18 hours huh? 18 is a multiple of 6. 6*3 is 18, 6*4 is 24. Every 18 hours would be 6, 24, 18, 12. Run the cron job at all of these times, have it check for a file /tmp/should_run that gets generated when the script should run.
Excellent idea, much better than mine. The only thing I would change would be to not put the "should_run" file in /tmp. It should go in a directory with more restrictions, so general users can't create it and make the job run at off hours. Aside from that, brilliant
Whatevah, I didn't put too much thought into the guts of it, just the abstract idea. :) But the at idea is MUCH better. Now who wants to answer my problems about CD burner and SBLive sound card? :) Misty On Wednesday 04 August 2004 20:15, Anders Johansson wrote:
Excellent idea, much better than mine. The only thing I would change would be to not put the "should_run" file in /tmp. It should go in a directory with more restrictions, so general users can't create it and make the job run at off hours. Aside from that, brilliant
On Wednesday 04 August 2004 14:00, Misty Stanley-Jones wrote:
Every 18 hours huh? 18 is a multiple of 6. 6*3 is 18, 6*4 is 24. Every 18 hours would be 6, 24, 18, 12. Run the cron job at all of these times, have it check for a file /tmp/should_run that gets generated when the script should run.
Not sure that I follow you. Would you mind elaborating? (Have you heard the story of the donkey that needed a 2x4 in the head to get its attention so it would plow?) -- ...CH "The more they over-think the plumbing, the easier it is to stop up the drain." Scotty
The Wednesday 2004-08-04 at 20:29 -0500, C Hamel wrote:
On Wednesday 04 August 2004 14:00, Misty Stanley-Jones wrote:
Every 18 hours huh? 18 is a multiple of 6. 6*3 is 18, 6*4 is 24. Every 18 hours would be 6, 24, 18, 12. Run the cron job at all of these times, have it check for a file /tmp/should_run that gets generated when the script should run.
Not sure that I follow you. Would you mind elaborating? (Have you heard the story of the donkey that needed a 2x4 in the head to get its attention so it would plow?)
Simple enough. Suppose you start at 00 hours. The next time, 18 hours later, would be at 18:00. The next time at 12:00 of the next day... you have an arithmetic series: day hour lapse ---+--------+------ 0 00:00 00 0 18:00 18 1 12:00 36 2 6:00 54 2 24:00 72 So you get a three days cycle. How to put that into crontab: "I'll leave that as an exercise for the reader", translated as "I feel lazy" :-p [...] Alternatively, what the original poster said, is to have the script run every day at hours 00, 6, 12, 18 and 24 (00), but check at the start when was the last time it run, calculating the time diference. Ie, the first time it would run at 00:00 hours, and would save a flag file somewhere stating that fact. The next cron job would start at 06:00, read the flag file, notice the time lapse not being 18 hours, ant exit. Same thing at noon, but at 6 PM the time lapse would be correct, it would run, and then, modify the flag file. Right? :-) -- Cheers, Carlos Robinson
Simple enough. Suppose you start at 00 hours. The next time, 18 hours later, would be at 18:00. The next time at 12:00 of the next day... you have an arithmetic series:
day hour lapse ---+--------+------ 0 00:00 00 0 18:00 18 1 12:00 36 2 6:00 54 2 24:00 72
So you get a three days cycle. How to put that into crontab: "I'll leave that as an exercise for the reader", translated as "I feel lazy" :-p
[...]
Alternatively, what the original poster said, is to have the script run every day at hours 00, 6, 12, 18 and 24 (00), but check at the start when was the last time it run, calculating the time diference.
Ie, the first time it would run at 00:00 hours, and would save a flag file somewhere stating that fact. The next cron job would start at 06:00, read the flag file, notice the time lapse not being 18 hours, ant exit. Same thing at noon, but at 6 PM the time lapse would be correct, it would run, and then, modify the flag file.
Right? :-)
-- Cheers, Carlos Robinson It can actually be fitted into a two-day cycle ...depending on the start time, I think. At any rate, I've elected to follow Scotty's advice & go your suggested route. -- ...CH "The more they over-think the plumbing,
On Thursday 05 August 2004 05:34, Carlos E. R. wrote: <SNIP> the easier it is to stop up the drain." Scotty
Hi, On Thursday 05 August 2004 06:46, C Hamel wrote:
On Thursday 05 August 2004 05:34, Carlos E. R. wrote: <SNIP>
Simple enough. Suppose you start at 00 hours. The next time, 18 hours later, would be at 18:00. The next time at 12:00 of the next day... you have an arithmetic series:
day hour lapse ---+--------+------ 0 00:00 00 0 18:00 18 1 12:00 36 2 6:00 54 2 24:00 72
So you get a three days cycle. How to put that into crontab: "I'll leave that as an exercise for the reader", translated as "I feel lazy" :-p
...
-- Cheers, Carlos Robinson
It can actually be fitted into a two-day cycle ...depending on the start time, I think. At any rate, I've elected to follow Scotty's advice & go your suggested route.
The least common multiple of 18 and 24 is 72, hence it requires a 72-hour (three-day) span to get exactly every 18 hours when only offsets within a 24-hour day (and day numbers) may be specified. I'm pretty unfamiliar with cron and haven't been following this thread all that carefully, but doesn't Carlos' approach require complete enumeration of the invocation intervals? Is there a way to get it to say "repeat this three-day pattern indefinitely"? Randall Schulz
On Thursday 05 August 2004 09:10, Randall R Schulz wrote:
I'm pretty unfamiliar with cron and haven't been following this thread all that carefully, but doesn't Carlos' approach require complete enumeration of the invocation intervals? Is there a way to get it to say "repeat this three-day pattern indefinitely"?
Run it every DAY, every 6 HOURS. :)
Randall Schulz
On Thursday 05 August 2004 07:56, Misty Stanley-Jones wrote:
On Thursday 05 August 2004 09:10, Randall R Schulz wrote:
I'm pretty unfamiliar with cron and haven't been following this thread all that carefully, but doesn't Carlos' approach require complete enumeration of the invocation intervals? Is there a way to get it to say "repeat this three-day pattern indefinitely"?
Run it every DAY, every 6 HOURS. :)
6 == 18? Randall Schulz
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. On Thursday 05 August 2004 09:59, Randall R Schulz wrote:
On Thursday 05 August 2004 07:56, Misty Stanley-Jones wrote:
On Thursday 05 August 2004 09:10, Randall R Schulz wrote:
I'm pretty unfamiliar with cron and haven't been following this thread all that carefully, but doesn't Carlos' approach require complete enumeration of the invocation intervals? Is there a way to get it to say "repeat this three-day pattern indefinitely"?
Run it every DAY, every 6 HOURS. :)
6 == 18?
Randall Schulz
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 ;)
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 ;) I know a bit about scripting but I perceive you are more of a veteran. I know quite a few commands but [again] you seem to be more of a veteran. That looks as if it'll work... I'm going to test it & see what happens! -- ...CH "The more they over-think the plumbing,
On Thursday 05 August 2004 11:49, Danny Sauer wrote: <SNIP> the easier it is to stop up the drain." Scotty
C Hamel wrote:
I know a bit about scripting but I perceive you are more of a veteran. I know quite a few commands but [again] you seem to be more of a veteran. That looks as if it'll work... I'm going to test it & see what happens!
That should be "I'm going to test it && see what happens!". ;-)
James wrote regarding 'Re: [SLE] Pullin' my hair out..[SOLVED (again)]' on Thu, Aug 05 at 12:21:
C Hamel wrote:
I know a bit about scripting but I perceive you are more of a veteran. I know quite a few commands but [again] you seem to be more of a veteran. That looks as if it'll work... I'm going to test it & see what happens!
That should be "I'm going to test it && see what happens!". ;-)
I dunno, he'll see what happens regardless of the outcome of the test, and will combine the test results with his observations to come up with a final result. The bitwise & might be appropriate - esp. in an environment with a short-circuit &&. ;) --Danny, who clearly doesn't have enough to do at work...
Randall R Schulz wrote:
On Thursday 05 August 2004 07:56, Misty Stanley-Jones wrote:
On Thursday 05 August 2004 09:10, Randall R Schulz wrote:
I'm pretty unfamiliar with cron and haven't been following this thread all that carefully, but doesn't Carlos' approach require complete enumeration of the invocation intervals? Is there a way to get it to say "repeat this three-day pattern indefinitely"?
Run it every DAY, every 6 HOURS. :)
6 == 18?
Randall Schulz
My question is, why 18 hours? Perhaps if the problem were better defined, we could provide a better solution.
Randall R Schulz wrote:
On Thursday 05 August 2004 07:56, Misty Stanley-Jones wrote:
On Thursday 05 August 2004 09:10, Randall R Schulz wrote:
I'm pretty unfamiliar with cron and haven't been following this thread all that carefully, but doesn't Carlos' approach require complete enumeration of the invocation intervals? Is there a way to get it to say "repeat this three-day pattern indefinitely"?
Run it every DAY, every 6 HOURS. :)
6 == 18?
Randall Schulz
My question is, why 18 hours? Perhaps if the problem were better defined, we could provide a better solution. ...Cuz that's what the boss wants. He didn't ask if Linux could do it easily. :-\ Wish he had... I'd have told him cron is the BW & it is based on 24hr time periods a la 'days'. I'm running it in cron on a two/three-day cycle. Frankly, creating an elaborate solution is not the kind of time I want to spend on it. -- ...CH "The more they over-think the plumbing,
On Thursday 05 August 2004 11:07, James Knott wrote: the easier it is to stop up the drain." Scotty
On Thursday 05 August 2004 05:34, Carlos E. R. wrote: Yup. Typical sysadmin approach, I think. ;) And you got that right about the "I feel lazy" part. :D
Simple enough. Suppose you start at 00 hours. The next time, 18 hours later, would be at 18:00. The next time at 12:00 of the next day... you have an arithmetic series:
day hour lapse ---+--------+------ 0 00:00 00 0 18:00 18 1 12:00 36 2 6:00 54 2 24:00 72
So you get a three days cycle. How to put that into crontab: "I'll leave that as an exercise for the reader", translated as "I feel lazy" :-p
[...]
Alternatively, what the original poster said, is to have the script run every day at hours 00, 6, 12, 18 and 24 (00), but check at the start when was the last time it run, calculating the time diference.
Ie, the first time it would run at 00:00 hours, and would save a flag file somewhere stating that fact. The next cron job would start at 06:00, read the flag file, notice the time lapse not being 18 hours, ant exit. Same thing at noon, but at 6 PM the time lapse would be correct, it would run, and then, modify the flag file.
Right? :-)
-- Cheers, Carlos Robinson
participants (14)
-
Anders Johansson
-
C Hamel
-
Carlos E. R.
-
Danny Sauer
-
Doug Currey
-
Dylan
-
Gerhard den Hollander
-
James Knott
-
Jerome Lyles
-
Jos van Kan
-
Ken Schneider
-
Misty Stanley-Jones
-
Patrick Shanahan
-
Randall R Schulz