Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have created a file called ntpdate in /etc/cron.hourly

#!/bin/sh
/usr/sbin/ntpdate-debian
date > /tmp/william_tmp
date > /william_tmp
date > ~/william_tmp
echo test

I also did Chmod 755 to this file.

However, I can't tell if the file has run or not!

The file is not created in any of the 3 directories.

If I manually run cd / && run-parts --report /etc/cron.hourly then the files are created and I get the echo.

Can anyone recommend (ideally step by step!) instructions to test that it is working?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

One major pitfall to cron is cron runs in an extremely limited shell environment, as a result a lot of variables aren't exported in to the environment, mainly $PATH. Make sure you use all absolute paths to executable, including common functions like echo, uptime, date, etc all need to use full paths (/bin/echo, /bin/date, /usr/bin/uptime). To determine the path to an executable, you can use the which command like so: which echo - this will show you the full path to that tool.

share|improve this answer
    
As discussed in chat, thanks for this and I really hope it will help someone else... Whilst I did the fall path to ntpdate, I am so used to Windows and echo/date being just "built in", I just didn't think I would need full path... learning a lot more about Linux and it makes perfect sense! –  wilhil Jun 11 '12 at 23:56

You should look in your /var/log/syslog log file. If a cron has run, it would have a line like:

Jun 11 19:09:01 penguin CRON[17376]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Jun 11 19:17:01 penguin CRON[17799]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

For troubleshooting tips, see https://help.ubuntu.com/community/CronHowto#Troubleshooting_and_Common_Problems

share|improve this answer
    
There isn't anything in Syslog and I can't see any reason why it would fail from that link :( –  wilhil Jun 11 '12 at 22:15
1  
If there are no entries in syslog (grep -i cron /var/log/syslog /var/log/syslog.1), start checking whether the cron daemon is running: ps uww -C cron should contain a line with a process. –  Lekensteyn Jun 11 '12 at 22:20
    
Sorry for being misleading, there are entires for Cron in the syslog, just nothing relating to this command... I know some jobs get run as every hour, I get a new mail alert... AFAIK, the ones that are working are from crontab, there is nothing in cron.hourly which is what I am trying to get working –  wilhil Jun 11 '12 at 22:25

Try changing the first line of your script (the interpreter) to:

#!/bin/bash

I've also had problems in the past, with environment variables and PATH issues. After changing the interpreter to bash my issues were gone.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.