4

I want to schedule a task for the second to the last day of each month. I have read this great article about shell scripting the execution. I have also seen that you can use "L" to represent the last day of the month, but I am using CentOS and cannot use the "L" construct.

I want to run the task at 11PM on the second to last day of each month. I hope to construct a command similar to:

0 23 27-30 * * [ "$(date +%d -d tomorrow" = "L" ] && $HOME/path/to/script

Knowing that I can't use L to represent the last day of the month, how can I use this logic to schedule my Cron job?

4
  • 2
    To anybody wanting to edit this question: The broken HTML is actually a part of the reason the crontab isn't working; by fixing them in the question you're mangling it.
    – Jenny D
    Jan 22 '15 at 11:02
  • Suggest to use "31", some month is 31 days long. It won't be called on 31. day of january, for example.
    – peterh
    Jan 22 '15 at 11:12
  • @PeterHorvath Please stop changing the content of the question. The broken HTML is actually part of the problem.
    – Jenny D
    Jan 22 '15 at 11:22
  • @JennyD Sorry, maybe I didn't follow the exact situation.
    – peterh
    Jan 22 '15 at 11:40
8

The code samples on that site are erroneous. They have certain shell characters replaced with HTML entities. The quotes also seem to be in the wrong places. I wonder if the author ever looked at that page when writing it...

Once we fix that, and then check to see if the first of the month is in two days rather than one...

0 23 27-30 * * [ $(date +\%d -d "2 days") == 01 ] && /where/is/my/script

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.