Perl Cron Scheduler: start at x time, execute ever

2019-08-29 03:47发布

问题:

I'm using perl cron, and I want to make a rule like this

run every xx min/hours starting at yy:yy time (until the end of time)

How would I put this into a cron string? perl:cron seems to use the same syntax as regular cron so a regular cron string should work

TIA!

回答1:

The short answer is that you will either need to write this yourself or find a different third-party package, due to your requirements. There's two things you're asking for that cron doesn't do:

  1. Run every X minutes.

    Say you want to run every 40 minutes, and you write this */40 * * * *. This actually runs every 60 minutes at 1:40, 2:40, etc.

  2. Start/Stop at time Y/Z.

    There's simply no cron syntax for this. You could use a couple more cronjobs to add/remove the main cronjob at the specified times, but this smells a lot like self-modifying code. Given the complexity (read: unreliability), it's probably better to find a different system.



回答2:

You can specify intervals with a slash. Here's every 5 minutes:

*/5 * * * *

This is every 2 hours:

0 */2 * * *

You cannot give a start/ end time in cron.