NaN
NaN

Reputation: 691

How can I run sub-minute cron jobs?

I would like to run a cron job every Wednesday at 10:31:10, but I just learned that crontab cannot run sub-minute jobs, so the closest I can get is 10:31 a.m. with the below code:

31 10 * * WED /file/to/run.py

Is it possible to hack around this, or are there other alternatives to cron that could do the job?

Upvotes: 0

Views: 1530

Answers (2)

kvantour
kvantour

Reputation: 26481

The easiest solution is to sleep for 10 seconds:

# .----------------- minute (0 - 59)
# |   .------------- hour (0 - 23)
# |   |  .---------- day of month (1 - 31)
# |   |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |   |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)
# |   |  |  |  |
# *   *  *  *  *     command to be executed 
  31 10  *  *  3     sleep 10 && /file/to/run.py

Upvotes: 2

TheWebs
TheWebs

Reputation: 12923

You can't. Cron has a 60 sec granularity.

You can though build a SH script that sleeps for ten seconds and then does X, set your cron job to run a script at 10:31 AM on a wednesday that then sleeps for 10 seconds, then do x.

Upvotes: 1

Related Questions