View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 11 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Tue Feb 13, 2007 9:55 am 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
I setup my crontab to kick off a few scripts I wrote but it never runs them. I have simplifed the setup currently to simply do an echo command to prove to myself that my cron is functioning properly:
Code:
# crontab -l
52 * * * * echo "test"


I sat here at 10:51 and waited as the system clock changed to 10:52 but I never saw the echoed text. I added that line via a crontab -e which I believe is correct. I know cron is running because my scripts in the /etc/cron.hourly are indeed running. What am I doing wrong?

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 10:03 am 
Offline
Joined: Tue Apr 13, 2004 6:51 pm
Posts: 890
Location: Groton, MA
where would you expect to see the output of the echo command?

Try changing the command to
Code:
52 * * * * echo "hello" > /tmp/cron.test 2>&1

then look in /tmp/cron.test file after the time has passed.

As a side note, remember that the shell that the command runs in is not the same as the user's login shell. If you are expecting environment variables, you will need to set them or source a profile script the the settings.

_________________
R5F1 - Dell P4 2.4Ghz 500MB - PVR250 x 2 - GeForce FX 5200 - Onboard sound/NIC 80GB ATA/250GB ATA/400GB SATA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 10:30 am 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
Thanks for the suggestion. That indeed works. So cron is working as it such be, the final step is getting my crontab to run my script. I currently have it in /home/mythtv and modified the line that preformed the echo to /home/mythtv/script but the script doesn't get called.

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 11:13 am 
Offline
Joined: Sat Feb 11, 2006 5:26 pm
Posts: 282
Location: Winnipeg - Canada
What do the permissions on the script look like? You can run it manually?

_________________
Currently Running:
Too lazy to update this with my current hardware, I'll redo it during my next install =)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 12:02 pm 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
I made the script with the root user since it's running root a root level program (ntpdate). It's permissions are 755. I can run it from the root user with no problems.

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 3:37 pm 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
What does the cron entry look like? And could you post the script in it's entirety?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 4:52 pm 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
Sure thing:

Code:
# crontab -l
@reboot /home/mythtv/gettime
0 0-23/4 * * * /home/mythtv/gettime


Script is:
Code:
#!/bin/sh
ntpdate ntp-3.vt.edu >> /var/log/gettime.log


---

I know I can circumvent this simply by replacing the
Code:
/home/mythtv/gettime
line with
Code:
/usr/sbin/ntpdate 2.pool.ntp.org >> /var/log/gettime.log
but that's not the point since there are other scripts that could be multiple lines that wouldn't work via that simple replacement.

Thanks in advance.

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 6:41 pm 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
graysky wrote:
I know I can circumvent this simply by replacing the
Code:
/home/mythtv/gettime
line with
Code:
/usr/sbin/ntpdate 2.pool.ntp.org >> /var/log/gettime.log
I believe this is the problem - Does it work if you add the path in the gettime script? As in
Code:
/usr/sbin/ntpdate ntp-3.vt.edu >> /var/log/gettime.log

You could also use the following to redirect standard error to your log (just in case):
Code:
/usr/sbin/ntpdate ntp-3.vt.edu >> /var/log/gettime.log 2>&1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 8:50 pm 
Offline
Joined: Sun Jun 12, 2005 10:55 pm
Posts: 3161
Location: Warwick, RI
Hi,

I saw somewhere that you may need a switch (a tip from Human I think), try:
/usr/sbin/ntpdate -u ntp-3.vt.edu >> /var/log/gettime.log 2>&1

Also nptd should be running and that should take care of time. I do put
/usr/sbin/ntpdate -u north-america.pool.ntp.org
at the end of /etc/init.d/bootmisc.sh so the clock starts off close and then ntpd does it's stuff.

Only exception I can see is for dial up where I run a script simular to the above line just to tweak the clock when I connect. You may want to also change the timezone table for the new rules starting March 11 if using an older version.

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 12:19 pm 
Offline
Joined: Tue Apr 13, 2004 6:51 pm
Posts: 890
Location: Groton, MA
its easy to capture errors that are thrown from the script with a little redirection.

Code:
0 0-23/4 * * * /home/mythtv/gettime 1> /tmp/cron.out 2> /tmp/cron.error


Here is a wiki entry I wrote a while back that discusses shell redirection if you want a little more info:

http://knoppmythwiki.org/index.php?page=IORedirection

_________________
R5F1 - Dell P4 2.4Ghz 500MB - PVR250 x 2 - GeForce FX 5200 - Onboard sound/NIC 80GB ATA/250GB ATA/400GB SATA


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 3:59 pm 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
Very cool, thanks for the info all. I'll check into it this weekend when I have a bit more free time.

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu