LinHES Forums
http://forum.linhes.org/

cron seems to be ignoring my crontab
http://forum.linhes.org/viewtopic.php?f=6&t=14161
Page 1 of 1

Author:  graysky [ Tue Feb 13, 2007 9:55 am ]
Post subject:  cron seems to be ignoring my crontab

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?

Author:  khrusher [ Tue Feb 13, 2007 10:03 am ]
Post subject: 

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.

Author:  graysky [ Tue Feb 13, 2007 10:30 am ]
Post subject: 

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.

Author:  rando [ Tue Feb 13, 2007 11:13 am ]
Post subject: 

What do the permissions on the script look like? You can run it manually?

Author:  graysky [ Tue Feb 13, 2007 12:02 pm ]
Post subject: 

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.

Author:  slowtolearn [ Tue Feb 13, 2007 3:37 pm ]
Post subject: 

What does the cron entry look like? And could you post the script in it's entirety?

Author:  graysky [ Tue Feb 13, 2007 4:52 pm ]
Post subject: 

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.

Author:  slowtolearn [ Tue Feb 13, 2007 6:41 pm ]
Post subject: 

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

Author:  mjl [ Tue Feb 13, 2007 8:50 pm ]
Post subject: 

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

Author:  khrusher [ Wed Feb 14, 2007 12:19 pm ]
Post subject: 

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

Author:  graysky [ Wed Feb 14, 2007 3:59 pm ]
Post subject: 

Very cool, thanks for the info all. I'll check into it this weekend when I have a bit more free time.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/