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.
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......)
If you use it in pair with some prog language you can do as follows, (e.g. golang):
_, minutes, _ := time.Now().Clock()
fmt.Sprintf("%d * * * *", minutes+1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With