?
Solved

UNIX Crontab running when not scheduled

Posted on 2015-02-03
3
Medium Priority
?
261 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
[X]
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
3 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 1000 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 1000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 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