3

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.

2 Answers 2

7
  • 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.

-1

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).

2
  • 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. Nov 22, 2010 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, 2010 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .