Search code examples
cron

Run immediately then every 4 hours in cron


How do you write a cron job which immediately run, then run on every hour divisible by 4? Say I started the script at 13:25, the job fires up right away, then the next run would be at 16:00, 20:00, 00:00 and so on.


Solution

  • For the first immediate run, just execute the command manually. Then set your cron up like this to have it execute continuously every 4th hour

     0 */4 * * * yourCommand
    

    This will run yourCommand every 4 hours (00:00, 04:00, 08:00......)