LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-27-2007, 02:38 PM   #1
holunde
LQ Newbie
 
Registered: Oct 2006
Posts: 3

Rep: Reputation: 0
Question Cron job won't redirect to log file


I have a small, strange issue with cron on Debian Etch

I have the following script, called ntpsync

#!/bin/bash
ntpdate 192.168.194.1 >> /var/log/ntpdate.log

I't owned by root and has executable permissions
I've added the following to roots crotab

20 * * * * /root/scripts/ntpsync

So the script is run once every hour.
And cron runs it every hour, BUT no output goes into ntpdate.log.

If I run the script manually, the out IS redirected into ntpdate.log

Has anyone got an idea, what is going on? There are no error messages and I have the same script running on another Etch machine without any problems at all.

??
 
Old 06-27-2007, 08:03 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,128
Blog Entries: 14

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
You need to insert the full path for ntpdate into your script. e.g.

/usr/sbin/ntpdate 192.168.194.1 >> /var/log/ntpdate.log

This is because the environment running cron isn't the same as the one you run when you do it from command line. It doesn't have the same $PATH as you would at command line so doesn't know where to find ntpdate itself.

Also the above only redirects stdout. Any errors wouldn't go to the log. You should redirect stderr to stdout so the errors get there as well. e.g.

/usr/sbin/ntpdate 192.168.194.1 >> /var/log/ntpdate.log 2>&1

The 2>&1 tells it to send file descriptor 2 (stderr) to file descriptor 1 (stdout).
 
Old 06-28-2007, 01:08 PM   #3
holunde
LQ Newbie
 
Registered: Oct 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Oh, of course. I see it now.
Thank you very much for your answer.
Strange that it works on the other machine. I must have changed
roots environment when I set it up. And forgotten about it...(!)
 
Old 06-28-2007, 03:05 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,128
Blog Entries: 14

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
No problem.

P.S. Any reason you don't want to use ntpd to keep your time accurate all the time instead of a cron entry that does it periodically using ntpdate?
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create cron job to empty mbox folder/file sjmo2 Linux - General 4 03-23-2006 03:39 PM
cron job to send file via ftp every 1 hour mcalizo Linux - Newbie 1 07-14-2004 04:50 AM
log cron job to capture errors if there are ashley75 Linux - General 1 05-21-2004 11:34 AM
cron job that email a text file paynsr Linux - Newbie 1 03-29-2004 02:36 PM
Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read efishta Linux - General 6 07-19-2003 11:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration