0

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$
Pab
  • 31
  • Do you mean to run the command after every 2:05? Or Every 2:00 and every 0:05? – Centimane Sep 19 '16 at 13:38
  • If you need help with what to input your crontab, try looking at this link: http://crontab.guru/ – ryekayo Sep 19 '16 at 13:39
  • Could you run it every 125 minutes? – Robert Fraser Sep 19 '16 at 13:52
  • You 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. https://blogs.oracle.com/gman/entry/periodic_and_scheduled_services_with – sleepyweasel Feb 02 '17 at 23:22

1 Answers1

4

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
user4556274
  • 8,995
  • 2
  • 33
  • 37
  • I couldn't make it work http://pastebin.com/xFSwpQnU – Pab Sep 19 '16 at 18:21
  • @PabloAngarano, my response works with bash and Vixie cron 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. – user4556274 Sep 19 '16 at 19:28
  • I believe the */5 syntax is specific to Vixie cron, hence the reason why this won't work on Solaris. You need to do 0,5,10,15,20,25,30,35,40,45,50,55 instead. Yes, I know: cumbersome. – peterh Oct 06 '16 at 14:33