Solved

UNIX Crontab running when not scheduled

Posted on 2015-02-03
3
244 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SSH commands for Nas4free 21 304
Oracle Finace 3 48
Sed question 2 49
Determine Who is Runnig my Bash Shell Script 4 22
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

746 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

9 Experts available now in Live!

Get 1:1 Help Now