Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to schedule a job to run on specific days of the week using crontab?

Posted on 2014-01-17
Medium Priority
Last Modified: 2014-01-17
I need to schedule a job that will run at 5 am from Tue-Fri, only 4 days in a week using crontab. But if Tue/Wed/Thur/Fri is the first day of the month then this job should not run. How do I accomplish that? Below scheduled job is not working as it runs on Saturday/Sunday. Please advise what changes do I need to make in a below scheduled job.

00 05 2-31 * 2-5 /export/home/adwadm/analytics/bin/ 2&>1
Question by:IT_ETL
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 68

Accepted Solution

woolmilkporc earned 2000 total points
ID: 39788707
00 05 * * 2-5 [[ "$(date "+\%d")" != "01" ]] && /export/home/adwadm/analytics/bin/ 2&>1

Please note the backslash "\"  in front of "%" - it is mandatory in crontab!

Author Comment

ID: 39789042
Hi woolmilkporc,

Thank you for quick response.

"00 05 * * 2-5 [[ "$(date "+\%d")" != "01" ]] && /export/home/adwadm/analytics/bin/ 2&>1"

Would you briefly explain  [[ "$(date "+\%d")" != "01" ]] &&?

Just a note, this job should not run on Sat, Sun, and Mon. Also, if it is the first day of the month then job should not run even though the day is Tue/Wed/Thur/Fri.

Should it be [[ "$(date "+\%d")" != "601" ]], why do we need "&&" in a above schedule.

Please advise.
LVL 68

Expert Comment

ID: 39789154
Why "601"? The job should not run on the first of a month, and date "+%d" is "01" on such a day.

!= means "not equal" (string comparison) and "&&" means "run the following statement if the previous expression returns "true", which is obviously not the case on the first of a month. It's just a short form of "if ... then ...".

The job is triggered by cron only on weekdays 2 to 5, which means Tuesday, Wednesday, Thursday and Friday.
Now our check comes into play. If we have a value other than "01" for date "+%d" then we run the script, otherwise we don't run it, but exit silently.

That's all.

Author Comment

ID: 39789987
Thanks woolmilkproc. It makes sense.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question