Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set cron job for every 45 days

Tags:

cron

I want to send an email after every 45 days using cron job. Since, i have already made php
script for email. So i want to execute it after every 45 days. Can you help me for this?

like image 910
Sachin Sawant Avatar asked Jan 02 '12 09:01

Sachin Sawant


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 is the use of * * * * * In cron?

* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.

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.)

What does cron 0 * * * * * mean?

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


2 Answers

Same can be implemented by scheduling 2 cron jobs for the script

Starting from 01-Jan-17:

0 0 1 1,4,7,10 *  abc.sh

0 0 15 2,5,8,11 *   abc.sh
like image 141
Parminder Avatar answered Oct 07 '22 18:10

Parminder


The script can be run daily and wrapped to check if the number of days modulo 45 equals to a constant:

10 13 * * *  test $(( `date +\%s`/24/60/60\%45 )) = 41 && your_script

I assumed 41 so the expression would evaluate to true today on 2012-01-12. Percent '%' is special character in crontab, it needs to be escaped.

like image 29
kubanczyk Avatar answered Oct 07 '22 18:10

kubanczyk