What's wrong with my cron.hourly configuration?
Every hour I get an email with error like this,
Subject: Cron <root@supa> root cd / && run-parts --report /etc/cron.hourly
/bin/sh: root: not found
Contents of /etc/crontab is as follows, either I remove user "root" or not (6th column), I get the same error.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
11 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
There are two files in my cron.hourly directory,
$ ll /etc/cron.hourly/
total 0
lrwxrwxrwx 1 root root 25 2009-10-29 09:24 ntpsync -> /home/<user>/bin/ntpsync
lrwxrwxrwx 1 root root 28 2009-10-23 10:33 foo -> /home/<user>/bin/foo
First script reads as follows,
$ cat ~/bin/ntpsync
#!/usr/bin/env bash
echo "user: $USER"
if [[ "$USER" == "root" ]] ; then
ntpdate ntp.ubuntu.com
else
sudo ntpdate ntp.ubuntu.com
fi
Even I remove both scripts in my /etc/cron.hourly/ directory, I still get the same error email every hour. I tried to restart cron and I still get the same error email. The next idea I have is to reboot but I'd avoid that.
$ sudo /etc/init.d/cron restart
My Ubuntu version is as follows,
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.1"
Update: I removed the 6th columns "root" from my /etc/crontab file earlier because when I searched online someone mentioned that could fix the problem. Now I think the problem was that I was messing around with the system crontab config instead of that of the root's.
$ sudo crontab -l
# m h dom mon dow command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Solution 1:
The default crontab file from the cron package (3.0pl1-100ubuntu2.1 this is the latest version of ubuntu 8.04) looks like this:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
You should just be able to take this and paste it into the file, but you might also want to make sure that you have the latest version of the package. You can do this by doing:
apt-get update
apt-get install cron
Update:
There are two different types of crontab's one is the system's crontab that is located in /etc/crontab
. This crontab has this fromat:
minute hour dayOfMonth month dayOfWeek userToRunAs restOfLineIsCommand
The other type is the users crontab's this can be modified by using the crontab
. The actual configuration is located in /var/spool/cron/crontabs/USERNAME
and is always executed as the user that owns it, and thous the format of that file is:
minute hour dayOfMonth month dayOfWeek restOfLineIsCommand
Solution 2:
I know you said you still get the errors after you remove the "root" in the sixth column, but it really looks like the issue.
For example, look at the other lines. They all start with "test". That's not a user, that's the beginning of a command. Removing the "root" would make your command start with "cd".
Especially since the error message says it can't find "root" which is the error you get when you try to run a program that doesn't exist.
So I'd say try removing that again.