Running Cron every 2 hours and 5 minutes
6,884
cron
does not naturally handle this kind of interval. You could try running a job every five minutes and adding a time check within the job to allow it to execute every 125 minutes:
*/5 * * * * [ $(expr $(date +\%s) / 60 \% 125) -eq 0 ] && date >> /tmp/cron-test01.out
Related videos on Youtube
![Pab](https://lh6.googleusercontent.com/-M-gthF-xp6o/AAAAAAAAAAI/AAAAAAAACZM/EurACA8Ar9I/photo.jpg?sz=256)
Author by
Pab
UNIX Admin: Solaris specialist, ZFS evangelist, passionate for users respect. shutdown ^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^
Updated on September 18, 2022Comments
-
Pab almost 2 years
I need create a cron job running every 2 hours and 5 minutes, is this possible? This doesn't work since is running each 5 minutes :(
user@server$ crontab -l 0,5,10,15,20,25,30,35,40,45,50,55 0,2,4,6,8,10,12,14,16,18,20,22 * * * date >> /tmp/cron-test01.out user@server$ cat /tmp/cron-test01.out Mon Sep 19 10:05:00 GMT 2016 Mon Sep 19 10:10:00 GMT 2016 Mon Sep 19 10:15:00 GMT 2016 Mon Sep 19 10:20:00 GMT 2016 Mon Sep 19 10:25:00 GMT 2016 Mon Sep 19 10:30:00 GMT 2016 user@server$
-
Centimane almost 8 yearsDo you mean to run the command after every 2:05? Or Every 2:00 and every 0:05?
-
Matej Vrzala M4 almost 8 yearsIf you need help with what to input your crontab, try looking at this link: crontab.guru
-
Robert Fraser almost 8 yearsCould you run it every 125 minutes?
-
sleepyweasel over 7 yearsYou don't note which version of Solaris. If you're using v11, you could look into using Periodic and scheduled services with SMF to see if that will better fit your requirements over using cron. blogs.oracle.com/gman/entry/…
-
-
Pab almost 8 yearsI couldn't make it work pastebin.com/xFSwpQnU
-
user4556274 almost 8 years@PabloAngarano, my response works with
bash
and Vixiecron
running on Linux. I don't have a solaris system to compare, but the same principal should work even if the syntax needs to be changed, for example, it may not be necessary to escape the%
symbols. -
peterh over 7 yearsI believe the
*/5
syntax is specific to Vixie cron, hence the reason why this won't work on Solaris. You need to do0,5,10,15,20,25,30,35,40,45,50,55
instead. Yes, I know: cumbersome.