Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a virtual server (debian) and the clock fails to sync from time to time (probably because i save/restore state with vboxheadlesstray).

To fix this issue I run dpkg-reconfigure ntp && ntpq -p, it works when I run it as root, but doesn't work with cron. I have added it in crontab -e (as root user) and is using this line:

1 * * * * dpkg-reconfigure ntp && ntpq -p > /dev/null 2>&1

My ordinary user user get mail about it saying /bin/sh: 1: dpkg-reconfigure: not found, why is my ordinary user getting the mail and not root and what do I need to change to make it work?

share|improve this question
up vote 2 down vote accepted

In Debian, dpkg-reconfigure is located under /usr/sbin, and root obviously has it in his $PATH, but cron limits $PATH to /usr/bin:/bin, even for root.
See man 5 crontab :

Several  environment  variables  are  set  up automatically by the cron(8) daemon.
SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab's owner.
PATH is set to "/usr/bin:/bin". HOME, SHELL, and PATH may be overridden by settings in the crontab;
LOGNAME is the user that the job is running from, and may not be changed.

So you would have to modify your crontab :

  • giving full path :
    1 * * * * /usr/sbin/dpkg-reconfigure ntp && ntpq -p > /dev/null 2>&1
  • or with modified $PATH :
    1 * * * * dpkg-reconfigure ntp && ntpq -p > /dev/null 2>&1

It would work, but it would not be clean :p
You'd better follow above recommandation, assuming you have a working ntp daemon, or just put that job instead :
10 * * * * /usr/sbin/ntpdate &>/dev/null

share|improve this answer

Better yet add the following to ntp.conf

tinker panic 0

That way you dont have to restart ntp (which is not good).

share|improve this answer
Didn't work. Server clock still unsynced with this. – Marwelln Jan 27 '14 at 10:03
What does ntpq -p say? – dfc Jan 27 '14 at 18:16

dpkg-reconfigure is located in /usr/sbin/ on my system:

martin@martin ~ % which dpkg-reconfigure

Check the PATH variable in your crontab, maybe it's missing the /usr/sbin/ directory?

Also, using dpkg-reconfigure just to force NTP to re-set the time doesn't seem like a particularly good idea, and ntpq -p > /dev/null 2>&1 doesn't seem to do anything useful. According to the manpage, -p just lists the peers, so running that and piping the output to /dev/null should do essentially nothing.

Why don't you just run /etc/init.d/ntp restart > /dev/null from your crontab?

share|improve this answer

Your Answer


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.