Score:-4

How to write cron expression for job should not run only last monday of the month

mv flag

My requirement -

  • I will schedule the job with cron expression.
  • The job is scheduled and runs every Monday morning 00:05 in the month
  • And it should run on the last Monday of the month.

Example : Consider this month I scheduled job for 3rd, 10th, 17th, 24th. I am expecting 24th job should not only run on 3rd, 10th, 17th , similar for all the month.

HBruijn avatar
in flag
Welcome to Server Fault! [Server Fault is a site for information technology professionals](http://serverfault.com/help/on-topic) -- as such we have certain professional expectations when people ask a question here, and one of those expectations is that your question shows you did some **research**, found and **read the vendor documentation** and/or **tried a solution** before asking the internet for help. You're not expected to solve everything yourself, but then at least you can [write a great question](http://meta.serverfault.com/a/3609/37681) that we can help you answer.
HBruijn avatar
in flag
Does this answer your question? [Why is my crontab not working, and how can I troubleshoot it?](https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it)
Score:0
cn flag

If you want it to run on a specific day, Monday, then you'll need to set it for the day of the week.

* * * * *

This is shown in the file /etc/crontab but to be clear, the asterisks represent, from left to right:

minute hour day of month month day of week

Right now, you have it set for those dates but clearly you don't want that because those dates won't always be Monday. To get what you want, use the following:

5 0 * * MON user command

That will run the job at 5 minutes after midnight or (12:05AM or 00:05AM) every Monday regardless of what date the Monday is.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.