Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron job every three days

Tags:

cron

Is it possible to run a cronjob every three days? Or maybe 10 times/month.

like image 400
tmartin314 Avatar asked Dec 28 '10 21:12

tmartin314


People also ask

How do I run a cron job every 2 days?

As we already know that the pattern * */2 * * * executes the task for every 2 hour, similary can * * */2 * * execute the task for every 2 day (once in 2 days).

What does cron 0 * * * * * mean?

*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.

How do I schedule a cron job every 3 hours?

Change Minute parameter to 0. You can set the cron for every three hours as: 0 */3 * * * your command here .. Save this answer.

How do I set a cron schedule?

Cron jobs are scheduled at recurring intervals, specified using a format based on unix-cron. You can define a schedule so that your job runs multiple times a day, or runs on specific days and months. (Although we no longer recommend its use, the legacy App Engine cron syntax is still supported for existing jobs.)


2 Answers

Run it every three days...

0 0 */3 * * 

How about that?

If you want it to run on specific days of the month, like the 1st, 4th, 7th, etc... then you can just have a conditional in your script that checks for the current day of the month.

if (((date('j') - 1) % 3))    exit(); 

or, as @mario points out, you can use date('k') to get the day of the year instead of doing it based on the day of the month.

like image 182
sberry Avatar answered Dec 04 '22 20:12

sberry


* * */3 * *  that says, every minute of every hour on every three days.   0 0 */3 * *  says at 00:00 (midnight) every three days. 
like image 30
tareco Avatar answered Dec 04 '22 19:12

tareco