Solved

UNIX Crontab running when not scheduled

Posted on 2015-02-03
3
250 Views
Last Modified: 2015-02-03
I would like for a cron to run at 9 am Monday-Friday IF it is the 25th->31st of the month so I put in the following crontab:

     0 9 25-31 * 1-5 date >> /home/jamtal/datelog.txt

The problem is that it runs at 9am Monday->Friday reguardless of the day of the month...

Is this a known bug in crontab?  I can't find any reference in the crontab manuals that this is an OR condition when other times it is an AND.

I have tried this on a Redhat Linux and Solaris system with the same result.

Thanks
0
Comment
Question by:James Talvy
3 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
ID: 40586513
man 5 crontab
...
       Note:  The  day  of  a  command's execution can be specified in the following two fields — 'day of month', and 'day of week'.  If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time.  For example,
       "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
0
 
LVL 1

Author Comment

by:James Talvy
ID: 40586563
So there is no way native to cron to accomplish what I want to do.

I guess I can wrap it in a shell script that checks for the day of week and exits if it is the weekend.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 40586825
You can add the "wrapper" to crontab:

0 9 * * 1-5 [[ $(date +\%d) -ge 25 && $(date +\%d) -le 31 ]] && date >> /home/jamtal/datelog.txt

Please note the backslashes (\) in front of the percent (%) signs, they're mandatory under cron!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

943 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now