Wednesday, February 2, 2022

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

Issue

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


Solution

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.



Answered By - fedorqui 'SO stop harming'
Answer Checked By - Dawn Plyler (WPSolving Volunteer)