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
Share:
6,884

Related videos on Youtube

Pab
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, 2022

Comments

  • Pab
    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
      Centimane almost 8 years
      Do you mean to run the command after every 2:05? Or Every 2:00 and every 0:05?
    • Matej Vrzala M4
      Matej Vrzala M4 almost 8 years
      If you need help with what to input your crontab, try looking at this link: crontab.guru
    • Robert Fraser
      Robert Fraser almost 8 years
      Could you run it every 125 minutes?
    • sleepyweasel
      sleepyweasel over 7 years
      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. blogs.oracle.com/gman/entry/…
  • Pab
    Pab almost 8 years
    I couldn't make it work pastebin.com/xFSwpQnU
  • user4556274
    user4556274 almost 8 years
    @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.
  • peterh
    peterh over 7 years
    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.