[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

UNIX Crontab running when not scheduled

Posted on 2015-02-03
3
Medium Priority
?
262 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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.
Suggested Courses

649 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