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>&1My 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?
dpkg-reconfigure: not found when running in cron
debian;cron
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>&1or with modified $PATH :PATH=/usr/bin:/bin:/usr/sbin1 * * * * dpkg-reconfigure ntp && ntpq -p > /dev/null 2>&1It would work, but it would not be clean :pYou'd better follow above recommandation, assuming you have a working ntp daemon, or just put that job instead :10 * * * * /usr/sbin/ntpdate &>/dev/null