LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


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

Rep: Reputation: 0
cron job running at unexpected times


Code:
#cat /etc/cron.d/script1
03 20 08 05 2 root /root/script1.sh 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
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
there are a few problems:
you need to write redirection as:
03 20 08 05 2 root /root/script1.sh >/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
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Your claims of other machines working as expected notwithstanding, the manpage for the crontab file (`man 5 crontab`) quite clearly states:
Quote:
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
prl77
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.
 
  


Reply



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
running cron jobs at random times fakie_flip Linux - Software 3 11-15-2017 12:54 PM
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
cron job not running vincebs Linux - Software 34 10-30-2004 01:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:53 PM.

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