Solved

UNIX Crontab running when not scheduled

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 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.:

690 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