Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to run cron every minute from 11:25 till 12:25 every day. Rest of time it should not run at all. The only idea i had is to use it like this

25-59/1 11 * * * /usr/bin/perl somescript.pl
0-25/1 12 * * * /usr/bin/perl somescript.pl

I am sure that there is more elegant solution, that i miss.

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted
  • You don't need the /1, it's implicit.
  • Put a #! /usr/bin/perl shebang into somescript.pl

Beyond that it's about as good as you can get, I think.

share|improve this answer
add comment

I want to run cron every minute from 11:25 till 12:25 every day. Rest of time it should not run at all. The only idea i had is to use it like this

Errr, probably not a good idea - cron is not particularly accurate at this level of granularity. And then there's the question of what happens when the program fails to complete in the allotted minute.

I'd recommend starting a wrapper script once a day from cron - implementing a loop with sleep to start up an instance of the program and wait for it to complete, with a time limit (and/or iteration limit).

share|improve this answer
    
While such a script can be simple, you will heavily rely on it always being started and stopped correctly. This requires some extra work, e.g. some logging will be nice. cron has been around since the early 1970s and is relied on by the OS, so it is already known to be reliable and it has standard resolutions for such things - better rely on it instead. –  reinierpost Nov 22 '10 at 13:05
1  
Read it again - I'm not suggesting cron is not unreliable - its just NOT DESIGNED to work at this level of granularity. Try adding '* * * * * date +%c >>somefile' and see what happens - even on a lightly loaded system you'll see variations of up to 10 seconds. –  symcbean Nov 24 '10 at 16:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.