Crontab scheduler to execute script every 45 days

Can someone please help me on how to schedule script to run every 45 days in crontab ?

Thanks,
Prince

It helps to have your OS like Ubuntu 16.1 or Solaris 10. It makes a big difference for date handling.

While you are giving that information:
Do you mean 45 days as:

  1. the first of month 1, 15th of month 2, first of month 4.... restart every January 1

  2. Today is the fifth. Add 45 dsays to that date, next time you run add 45 days. This means that every year the run shifts "backwards" by five days, and on leap year 6 days.

Calendars are not simple, we need to know exactly what your requirement for 45 days is.

Sure, Am using red hat linux version 6. I have script for cleaning logs. I have to cleanup logs every 45 days. So i have to execute script every 45 days.

For example, If i run the script today then next script execution should be after 45 days.

Thanks,
Prince

ever considered using at command?
The idea in your job execution, to do self execution by calling itself in 45 days using at...
I dp that sometimes...

1 Like

try adding to cron:

00 00 * * * test $(( ($(date +\%s)/24/60/60) \% 45 )) = 0 && /path_to_script/clean_up_script
2 Likes

Have you investigated the logrotate command and configuration? That might save you having to craft your own. You can force a rotation based on several criteria as it suits your needs.

Robin

1 Like