LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2005, 11:53 PM   #1
tassinari
LQ Newbie
 
Registered: Mar 2005
Location: Waltham, MA
Distribution: SUSE 9.1
Posts: 15

Rep: Reputation: 0
cron problems


Hi, I am trying to synchronize my clock every hour through a cron job.

'crontab -u root -l' gives me:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.12634 installed on Mon Jan 1 12:25:32 2001)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
26 * * * * /usr/sbin/ntpdate north-america.pool.ntp.org

yet it does not work, but I am sure the ntpdate command is working because I can run it from the command line.

I think the cron dameon is running beacuse 'ps aux|grep cron' gives me:
root 12013 0.8 0.2 1400 596 ? Ss 11:54 0:22 cron
root 12902 0.0 0.1 1520 484 pts/0 R+ 12:37 0:00 grep cron

Am I overlooking anything?

Thanks in advance.
 
Old 04-02-2005, 02:01 AM   #2
hallamigo
Member
 
Registered: Feb 2004
Location: Utah, USA
Distribution: Debian
Posts: 230

Rep: Reputation: 31
Not sure if you're overlooking something, but here is how I handle mine on Slackware 10.1 (running 'crontab -e' doesn't work for me - something to do with my editor settings).

As root I do the following:

cd /var/spool/cron/crontabs/
vi cron_holder (make entries/edits, save changes)
crontab cron_holder

This creates a cron.update file in the same directory that gets processed on the next cron cycle (not sure if I'm explaining it right) and copies your changes into the 'root' file which is run by cron - editing the 'root' file directly is a bad idea and the changes won't go into affect.

Hope that helps.
 
Old 04-02-2005, 06:33 AM   #3
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
Well, I think you can always edit the cron job by simply using 'crontab -e'.

If you want to schedule the job as root or someone, you can su to root (or that someone else) before you do 'crontab -e'

As for tassinari's issue, my guess is the cron job definition does not like the space in the command. Try wrap this command in a shell script.

i.e. put the lines
Code:
#!/bin/bash
/usr/sbin/ntpdate north-america.pool.ntp.org
into, says, time.sh (make sure the x permission are set on this file)

then crontab -e and change the line into
Code:
26 * * * *  /path/to/time.sh

Hopefully it works.
 
Old 04-02-2005, 07:16 AM   #4
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 33
what are the mails your crontab retuns?

if you dont have any: add this to your crontab in the first line (just for debug purposes!)
MAILTO=you@example.com
 
Old 04-02-2005, 11:47 AM   #5
tassinari
LQ Newbie
 
Registered: Mar 2005
Location: Waltham, MA
Distribution: SUSE 9.1
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks to everyone for their help but the problem fixed itself. I woke this morning and started the computer and the cron job ran. I changed nothing from last night. My guess is the cron dameon wasn't working last night but did work this morning after booting. Why it was'nt working last night is beyond me though.

Thanks again!
 
Old 04-02-2005, 12:52 PM   #6
hallamigo
Member
 
Registered: Feb 2004
Location: Utah, USA
Distribution: Debian
Posts: 230

Rep: Reputation: 31
Linux = when all else fails, reboot
Windows = first step, reboot
 
Old 04-02-2005, 04:46 PM   #7
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
When, in this case, you do not have to reboot either... :-)

If you are confident that your job definition is fine but it's justing not running, you may try

Code:
ps auxw
first to check if there is any crond processes stalled.

I saw this kind of problem before. If it is the case, kill the crond and that's. No need to reboot.
 
Old 04-02-2005, 06:06 PM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0, RHEL5,6), CentOS, SuSE (10.x, 11.x, 12.2, 13.2), Solaris (8-10), Tru64, MacOS, Raspian
Posts: 1,113

Rep: Reputation: 65
Re: cron problems

Quote:
Hi, I am trying to synchronize my clock every hour through a cron job.

Am I overlooking anything?
I'm wondering whether setting up the NTP service wouldn't be easier than the cron job. Yes, you do need to track down a suitable time server (see the lists on http://ntp.isc.org/bin/view/Servers/WebHome) but once that's done it's pretty much "set and forget".
 
Old 04-02-2005, 11:11 PM   #9
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
rnturn is right. I'd overlooked the real issue.
 
  


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
cron problems deadite66 Linux - General 0 08-06-2005 07:29 PM
Cron Problems eagle683 Programming 6 07-26-2005 07:26 PM
Cron Problems DNAphil Linux - Newbie 1 07-12-2005 08:56 AM
problems using cron Mugatu Linux - Software 3 02-26-2004 03:15 PM
Cron problems goochable Linux - Newbie 3 04-17-2001 08:43 AM


All times are GMT -5. The time now is 01:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration