user22
user22

Reputation: 1259

How can make cron job which happen at different hours and minutes

I want to make crontab where script occurs at different minutes for each hour like this

35 1,8,12,15,31 16,18,21 * * 0,1,2,3,4,5,6 python backup.py

I want script to run at 16hour and 31 minutes but it is giving me error bad hour

i want the cron occur at

1:35am , then 16:31, then 21:45

Upvotes: 5

Views: 10887

Answers (2)

Dan
Dan

Reputation: 2509

If the system which you are on has systemd, You can look into systemd timers(https://www.freedesktop.org/software/systemd/man/systemd.time.html). Then you might be able to achieve the randomness using the RandomizedDelaySec setting and an OnCalendar setting which will schedule the service to run every hour or interval you set plus will generate a RandomizedDelaySec at every run so that the interval is random.

Upvotes: 0

fedorqui
fedorqui

Reputation: 290285

As there is not a pattern that can match the three times, it is not possible to schedule that just with one crontab expression. You will have to use three:

45 21 * * * python backup.py
31 16 * * * python backup.py
35 1 * * * python backup.py

Note also that python backup.py will probably not work. You have to define full path for both files and binaries:

35 1 * * * /usr/bin/python /your/dir/backup.py

Where /usr/bin/python or similar can be obtained with which python.

Upvotes: 8

Related Questions