Ubuntu – How to tell if the hourly cron job has run


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

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?

Best Answer

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.

Related Question