1

I want to run a script that generates a weekly report every Saturday night at 11 PM, and another script that generates a monthly report on the 1st of each month.
I don't want the weekly report to run if Saturday falls within 3 days of the 1st of the month.

here is once a month:

0 23 1 * * /home/me/monthly.sh

here is as close to the weekly entry as I can figure out...

0 23 4-? * 6 /home/me/weekly.sh

Can I replace that question mark with something that means "3 days before the end of the month"? Or is there some other approach that would suit my purpose?

Being able to specify some number of days before the end of the month seems like a feature you'd want to have in a job scheduler, so I'll be a bit surprised if crontab can't do it.

My alternative would be to check the date in weekly.sh, and stop if I'm within 3 days of the 1st.

  • I think I'm going to make a single script, submit it daily in crontab, and have the script use date to see if it should run a report or not, and which one. – zambo Jan 4 '17 at 15:45
0
0 23 * * 6 [ $(date +%e -d "next saturday") -gt 3 ] && /home/me/weekly.sh
  • Just pointing out the obvious: This requires GNU date. – Kusalananda Jan 4 '17 at 9:31
  • This tells me if next Saturday is after the 3rd, which I'd already figured out how to do. Also, if I'm just going to string commands together, I'll do that in my script, as I said. – zambo Jan 4 '17 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.