I have a sudo crontab like this to sync time:

# m h dom mow dow command

0 6 * * * ntpdate >> /var/mylog/ntp.log
0 7 * * * /var/mylog/backup.sh >> /var/mylog/backup.log

The problem I am having is that the first line (ntpdate) never seems to execute. If I run it manually with sudo that line works. cron does run the backup.sh at the 7, but it never executes then ntp sync at 6. The syslog doesn't seem to show anything.

System is Ubuntu 10.04 LTS.

  • 4
    Running ntpdate via cron is almost always the wrong thing to do. Why don't you install the ntp daemon? As for your problem, check the PATH? give the fully full path to ntpdate? – Zoredache Oct 17 '12 at 23:52
  • You are correct, in that PATH is the problem. I dont run ntpd because this system is on a vessel that connects and disconnects at certain times having seperate timing in all the conf files of different daemons is a pain. Why is ntpdate via cron 'wrong'? Why wouldn't it work? – kiasecto Oct 17 '12 at 23:59
  • ntpdate is deprecated; its functionality is now available with the -q option to ntpd. Since you have an intermittent network connection, it's probably best to run ntpd -q in a local script that fires whenever the network connection comes up, rather than within crontab. You'll also need to add iburst in /etc/ntpd.conf. – Michael Hampton Oct 18 '12 at 2:46

When a cron job runs it does not have the full environment of a user, which means that the problem will be that ntpdate simple isn't found. To be sure you should specify the full path to a file to be executed in a cron task.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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