CentOS Icon CentOS Logo
CentOS Text
   
  
www.centos.org Forum Index
   CentOS 5 - Server Support
  Strange issue with crond in /etc/cron.d

 

 Bottom   Previous Topic   Next Topic
  •  Rate Thread
      Rate this Thread
      Excellent
      Good
      Average
      Bad
      Terrible
Poster Thread
  •  tnine
      tnine
Strange issue with crond in /etc/cron.d
#1
Peeking in the Member Window
Joined: 2006/5/3
From
Posts: 19
Hi all,
I've used cron for quite some time and never had any issues. I have a job that I want to run at minutes 0, 15, 30, 45 (every 15 but must be on quarter of the hour) between 10 am and 8 pm every day of the year. I've created the file "notifyoncall" and placed it in /etc/cron.d. Here are the file contents.

#run every quarter of an hour only from 10 am to 8 pm

0,15,30,45 10-20 * * * root /usr/local/notifyoncall/notifyoncall.sh


If I run the script /usr/local/notifyoncall/notifyoncall.sh with the full path everything works well. I have no idea why this isn't working, it just seems cron isn't executing the job, but the nightly and user cron jobs execute fine. Any help would be greatly appreciated.

Thanks,
Todd
Posted on: 2009/11/6 3:29
Create PDF from Post Print
Top
  •  pschaff
      pschaff
Re: Strange issue with crond in /etc/cron.d
#2
Moderator
Joined: 2006/12/13
From Tidewater Virginia, North America
Posts: 3404
0,15,30,45 10-20 * * * /usr/local/notifyoncall/notifyoncall.sh


Drop the "root".
_________________
Phil
Required reading: FAQ & Readme first ; Search hint: google "your topic site:centos.org"; Smart Questions
Posted on: 2009/11/6 13:09
Create PDF from Post Print
Top
  •  TrevorH
      TrevorH
Re: Strange issue with crond in /etc/cron.d
#3
Regular Board Member
Joined: 2009/9/24
From Brighton, UK
Posts: 79
No, the OP is in /etc/cron.d not in /etc/cron.daily so the root is needed.

I think you should look in /var/log/cron and see if the script is being invoked. If it is then there is a problem within your script and the most likely answer then is that you are missing full paths to the executables that you are running inside the script. Cron scripts are invoked with a very stripped down path and few environment variables so what works from a command line may not necessarily work from cron. Make sure that you use, for example, '/bin/ls' and not just 'ls' inside your cron script or set the PATH to include the locations you want searched.
Posted on: 2009/11/6 13:38
Create PDF from Post Print
Top
  •  pschaff
      pschaff
Re: Strange issue with crond in /etc/cron.d
#4
Moderator
Joined: 2006/12/13
From Tidewater Virginia, North America
Posts: 3404
OK, did not read carefully enough. I always use "crontab -e" ("man crontab"; "man 5 crontab") and the user field is not used there. Using "crontab -e" should work following my example as root.

Also correct that adding full paths is often necessary in cron jobs, and will never hurt, but don't think that's required for /bin and /usr/bin - at least I have crontab scripts that do not use full paths for things that live there. I believe full paths are required for /sbin, /usr/sbin, and pretty much anywhere else.
_________________
Phil
Required reading: FAQ & Readme first ; Search hint: google "your topic site:centos.org"; Smart Questions
Posted on: 2009/11/6 13:59
Create PDF from Post Print
Top
  •  tnine
      tnine
Re: Strange issue with crond in /etc/cron.d
#5
Peeking in the Member Window
Joined: 2006/5/3
From
Posts: 19
Thank you for your help guys. I wasn't sure where cron logged, I didn't think to look for one as I've never had a cron job not work(duh!)! Anyway, after looking through the log I have this entry.

(*system*) BAD FILE MODE (/etc/cron.d/notifyoncall)

Apparently my permissions of 755 weren't well liked. I chmod'ed my definition file to 644 and everything works perfectly. Thanks for your help guys. It's greatly appreciated. I have one last question. My root mail is filling up and I don't want notification every time my script runs. Can I redirect stdout to /dev/null or is there some other way to avoid it putting something in root's mail inbox?

Thanks,
Todd
Posted on: 2009/11/7 2:45
Create PDF from Post Print
Top
  •  AlanBartlett
      AlanBartlett
Re: Strange issue with crond in /etc/cron.d
#6
Professional Board Member
Joined: 2007/10/22
From ~/Earth/UK/England/Suffolk
Posts: 4294
Quote:
Can I redirect stdout to /dev/null or is there some other way to avoid it putting something in root's mail inbox?

All output produced by a cron job is, unless explicitly handled, mailed to root (or another ID, if the MAILTO= line is modified).

So, if you do not need to see the output, just redirect it to the null device.

If you would like to keep the output of the last run of the cron job, redirect the output to a file.
_________________
Alan.

100% CentOS, Linux & Unix. Co-founder of ELRepo.
Posted on: 2009/11/7 11:22
Create PDF from Post Print
Top
 Top   Previous Topic   Next Topic

 


 You cannot start a new topic.
 You can view topic.
 You cannot reply to posts.
 You cannot edit your posts.
 You cannot delete your posts.
 You cannot add new polls.
 You cannot vote in polls.
 You cannot attach files to posts.
 You cannot post without approval.




"Linux" is a registered trademark of Linus Torvalds. | All other trademarks are property of their respective owners. | All other content is Copyright @ 2004-2009 by the CentOS Project or "each individual contributor (forums, comments, etc.) unless otherwise assigned".| Theme based on a theme by 7dana.com