Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-29-2012, 01:33 PM   #1
LQ Newbie
Registered: May 2011
Posts: 6

Rep: Reputation: 0
cron job running at unexpected times

#cat /etc/cron.d/script1
03 20 08 05 2 root /root/ 2>&1 >/dev/null
Two problems:
  1. I only intended to run this script one time, but it runs every Tuesday for some reason. I have other machines with similarly narrowed down schedules and they work as expected.
  2. I'm redirecting output to /dev/null to not receive an email. I know I can also use the MAILTO="" directive, but I'm pretty sure I've successfully used this method in the past.

Thank you for your time everybody.
Old 05-29-2012, 01:38 PM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 6,386

Rep: Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722Reputation: 1722
there are a few problems:
you need to write redirection as:
03 20 08 05 2 root /root/ >/dev/null 2>&1 (this will redirect stderr to stdout and than stdout to /dev/null) otherwise you will redirect stdout to /dev/null and stderr to stdout.
The number 2 before root (fifth field) means you want to execute it on every Tuesday (see man page of crontab)
1 members found this post helpful.
Old 05-29-2012, 01:45 PM   #3
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 2,059

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Your claims of other machines working as expected notwithstanding, the manpage for the crontab file (`man 5 crontab`) quite clearly states:
Note: The day of a commandís execution can be specified by two fields ó day of month, and day of week. If both fields are restricted (ie, arenít *), 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.
1 members found this post helpful.
Old 05-29-2012, 06:41 PM   #4
LQ Newbie
Registered: May 2011
Posts: 6

Original Poster
Rep: Reputation: 0
Thank you gentlemen. Upon further examination, I do see that the other jobs I referenced as working as expected, were in fact running every week, I just didn't realize it because there was nothing for them to do during that time frame. This was a good lesson, my understanding of the crontab table format was incorrect, I thought all restricted (non *) fields had to match.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job is not running akshathajagadish Linux - Newbie 2 10-15-2009 07:21 PM
Running a Cron Job landysaccount Linux - Newbie 6 02-04-2009 05:29 PM
cron executes job three times at the same time rimvydazas Linux - Software 2 02-07-2008 02:47 PM
running cron jobs at random times fakie_flip Linux - Software 1 11-23-2007 05:32 PM
cron job not running vincebs Linux - Software 34 10-30-2004 01:27 PM

All times are GMT -5. The time now is 10:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration