Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make cron run something every "N"th minute, where n % 5 == 1?

I know that I can have something run every five minutes in cron with a line like:

 */5 * * * * /my/script 

What if I don't want it running at 12:00, 12:05, 12:10, but rather at 12:01, 12:06, 12:11, etc? I guess I can do this:

 1,6,11,16,21,26,31,36,41,46,51,56 * * * * /my/script 

...but that's ugly. Is there a more elegant way to do it?

like image 370
mike Avatar asked Jan 22 '09 22:01

mike


People also ask

How do you write a cron expression every 5 minutes?

Execute a cron job every 5 Minutes If you specify */5 in the 1st field, it runs every 5 minutes as shown below. Note: In the same way, use */10 for every 10 minutes, */15 for every 15 minutes, */30 for every 30 minutes, etc.

How do I run a cron job after every minute?

Execute Cron Job After System Reboot. Setup and Run PHP Script As A Cron Job. Run crontab job every minute on a Linux or Unix-like system.

How do I run a cron job every 5 seconds?

Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .


1 Answers

1-56/5 * * * * /my/script 

This should work on vixiecron, I'm not sure about other implementations.

like image 132
David Z Avatar answered Sep 21 '22 06:09

David Z