Crontab Every 5 Minutes

Run cron every 5 minutes in specific time span

There's nothing wrong with explicitly listing the times you need if there's no appropriate shortcut:

# Tuesday + Wednesday 8pm - 10pm
*/5 20-22 * * 2,3 $COMMAND

# Friday 8.30pm - 10.30pm
30,35,40,45,50,55 20 * * 5 $COMMAND
*/5 21 * * 5 $COMMAND
0,5,10,15,20,25,30 22 * * 5 $COMMAND

# Saturday 3.30pm - 5.30pm and 6.30pm - 8.30pm
30,35,40,45,50,55 15,18 * * 6 $COMMAND
*/5 16,19 * * 6 $COMMAND
0,5,10,15,20,25,30 17,20 * * 6 $COMMAND

# Sunday 3.30pm - 8.30pm
30,35,40,45,50,55 15 * * 0 $COMMAND
*/5 16-19 * * 0 $COMMAND
0,5,10,15,20,25,30 20 * * 0 $COMMAND

Can a cron job be set to run every hour at 5 minutes after the hour?

Yes - you can specify the minuted value as 5, and leave the rest as wildcards:

5 * * * *

How to run a cronjob every X minutes?

In a crontab file, the fields are:

  • minute of the hour.
  • hour of the day.
  • day of the month.
  • month of the year.
  • day of the week.

So:

10 * * * * blah

means execute blah at 10 minutes past every hour.

If you want every five minutes, use either:

*/5 * * * * blah

meaning every minute but only every fifth one, or:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * blah

for older cron executables that don't understand the */x notation.

If it still seems to be not working after that, change the command to something like:

date >>/tmp/debug_cron_pax.txt

and monitor that file to ensure something's being written every five minutes. If so, there's something wrong with your PHP scripts. If not, there's something wrong with your cron daemon.

When a cron job is set to run every 5 minutes, does it run every 5 minutes from the moment it's added?

*/5 in the minutes field means "from first to last, every 5 minutes", so it will start running at 0 minutes past the hour and every 5 minutes thereafter.

How can I run a cron job every 5 minutes starting from a time other than 0 minutes?

Syntax 1

*/5+2 * * * * 1st-script
*/5+4 * * * * 2nd-script

For future reference take a look at this online Cron Job Generator.

Syntax 2

Since there are several reports that the + syntax is not working on Ubuntu 14.04, here's a variation:

2-59/5 * * * * 1st-script
4-59/5 * * * * 2nd-script

This will result in the 1st script to run every 5 minutes starting with an offset of 2 minutes at the beginning of each hour and the 2nd script to behave the same with an offset of 4 minutes.



Related Topics



Leave a reply



Submit