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?
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).
* * * * * 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.
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.)
*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.
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
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.
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