Bloggers Wanted
We're looking for people to help with the main blog. If you are consistent, knowledgeable and you're into it, please drop me a note.
|
|
|
|
|
Ns Ehrlich
Senior Boarder
Posts: 67
|
|
How do you run the crontab every 55 days?
|
|
The administrator has disabled public write access. |
mystic_moose
Senior Boarder
Posts: 66
|
|
If the script may fail it would be better to put the rescheduling at the start, that will give behaviour closer to that of cron. (since cron will still run it again even if it fails)
Since a script may have several exit points you would have to do the rescheduling at each of them, better to do it at the start.
Consider a backup script that has something like: if [$files_to_back_up = 0] ; then exit 0; fi
That would break if the rescheduling is at the end, but work fine if it's at the start.
regards
|
|
The administrator has disabled public write access. |
Etotogeya
Senior Boarder
Posts: 66
|
|
Yep. That's for sure.
The post was specific about it being every 55 days: 'How do you run the crontab every 55 days?' You don't, with cron. Anything's possible I suppose, but that would involve more work than is necessary. Like a routine for adding 4752000 to the epoch time for the given day/time and [re]scheduling it that way. Laziness can be a virtue.
Previously suggested, although the '-f <file>' at option is definitely better than an echo. The only minor issue here is saying 'now' could subtly allow drift in the time that the script runs, depending on where it the reschedule is dropped into the job. Which is why stating a specific time would be a more clean way of doing it. It's the OP's preference, though.
Guessing that it's not for a backup.
|
|
The administrator has disabled public write access. |
ppreddy
Senior Boarder
Posts: 79
|
|
A programmer will tell you that's what flow-control and testing is for, though. Like was previously mentioned, it would blow to hang around for 55 days to see the job fail.
OT. Define a brief function and reuse it as necessary. If a script gets to that point then continually retyping a reschedule line is pretty silly.
Of course *that* would break.
|
|
The administrator has disabled public write access. |
nfdouglas
Senior Boarder
Posts: 69
|
|
I do a bit of programming, but not with awk, and this one baffles me.
Running 'date' in seconds gives: $ date +%s 1055424159
Which is a reasonable amount since 1970: Enter math: 33.5*365.25*24*60*60 answer = 1057179600
But if I use that number in your command: $ date +%s|awk '($0/(24*60*60))%55;' 1055424084 $ date +%s|awk '($0/(24*60*60));' 1055424104
As opposed to: Enter math: (1055424159)/(24*60*60) answer = 12215.5573958333 Enter math: (1055424159)/(24*60*60)%55 answer = 5
And if I enter your commands with the seconds hard coded: $ awk '(1055424159/(24*60*60))%55;' $ awk '(1055424159/(24*60*60));' Both lines above send my bash off into limbo until I 'ctrl c' it. Are you sure of your code, and if so, could I bother you to explain it?
Of all the explanations given, I found your APPROACH the most ingenius...once I can get the actual math to work, that is.
Best regards,
|
|
The administrator has disabled public write access. |
audibert
Senior Boarder
Posts: 68
|
|
that's pretty cool
|
|
The administrator has disabled public write access. |
SorroW
Senior Boarder
Posts: 70
|
|
1. you used ( ) instead of { }
2. the way awk is used here, it's not going to print the output of the math.
if you look at the original text, the math is used to return an exit code. it's not printed to the console either in that version or this one. For that, I think you would have to use
$ date +%s|awk '{ print ($0/(24*60*60)); } '
|
|
The administrator has disabled public write access. |
blueice
Senior Boarder
Posts: 72
|
|
Neat!
Yep.
Ah. That's not what he wrote. You've omitted the verb 'exit'
It gets awk to exit with a status code in the range 0..54, based on the current date. If it's 0 (i.e. once every 55 days), then the |lets the real program do the work. Otherwise it doesn't.
Try this: date +%s awk 'print ($0/(24*60*60))'
The awk 'program' iterates for each line of input, which is provided in $0. There's only one line from date, so it runs precisely once.
Then try this with varying values instead of 55 to see what's up: date +%s awk 'print ($0/(24*60*60)%55)'
And then this: date +%s awk 'exit ($0/(24*60*60)%55)'; echo exit status is $?
Remember that only if the exit status is 0 would the OP's real program run: date +%s awk 'exit ($0/(24*60*60)%55)' |echo running
|
|
The administrator has disabled public write access. |
Steven_Osteon
Senior Boarder
Posts: 62
|
|
'DB'
|
|
The administrator has disabled public write access. |
sorrsuki
Senior Boarder
Posts: 74
|
|
{Embarassment}
I think I realized that, but my brain didn't twig. So much for trying to explain someone else's code - as you can see I was all the way there, but copied his |instead of using &&. Sigh.
Thanks for the correction.
|
|
The administrator has disabled public write access. |
0Kelvin
Senior Boarder
Posts: 73
|
|
I was thinking more along the lines of a script that's expected not to complete once in a while. Using crontab it would still run the next time.
Good point, defining an exit_and_cleanup function would accomplish the same thing.
And since we really don't know what the every 55 days is doing and how I still believe that doing the rescheduling at the start is the safest thing.
Yet that awk trick (once the |is switched to && ) was beatiful and might be better, especially if the script is called manually once in a while.
regards
|
|
The administrator has disabled public write access. |
|
|
|