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 )
The default crontab file from the cron package (3.0pl1-100ubuntu2.1 this is the latest version of ubuntu 8.04) looks like this:
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:
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: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: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.
Your
/etc/crontab
looks funny indeed. Every line should actually have a user column actually, which is the funniest part. For example, mine reads:By the way, it is usually not a good idea to touch this file. If you need to add more generic crontabs, use
/etc/cron.d
for this. You can try to restore the default configuratino for the cron package with:and see if it fixes the issue.
There are really two issues at play here. One (the more obvious) is the improper 6th column in root's personal crontab. The second silent one - is that ever command after the hourly cron line in
/etc/crontab
is not executing properly. The fixes are below:You can remove the bogus user crontab file by running
sudo crontab -r
Once that's complete you'll need to add the root user in the
/etc/crontab
file for each line after the hourly cron line - like so:This should resolve those email issues.
Do it:
And do NOT do it:
Instead, edits file /etc/crontab manually.