Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 )
share|improve this question
1  
Does your user - or the root user - have anything in their personal cron files? crontab -l –  Marco Ceppi Aug 25 '10 at 19:41
    
@Marco Ceppi, I think that maybe the problem, please see my Update in the original post. –  grokus Aug 25 '10 at 21:46
    
I just did "sudo crontab -e" and removed "root" from all 4 lines and restart cron. I will report back later. –  grokus Aug 25 '10 at 21:48
    
Did it fix the issue @grokus? Like I said in my answer, you should really never touch /etc/crontab directly, but instead add files in /etc/cron.d, /etc/cron.hourly, etc. –  ℝaphink Aug 25 '10 at 21:48
    
@grokus: Consider reinstalling the cron package though. You really should have root in every line of /etc/crontab. –  ℝaphink Aug 25 '10 at 21:50

5 Answers 5

up vote 6 down vote accepted

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
share|improve this answer

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.

share|improve this answer
    
Agreed. This seems to be the point. –  ddeimeke Aug 25 '10 at 20:36
1  
The issue is - his syntax is correct - if he is in-fact running cat /etc/crontab the first line is right - the others are not. But if he is actually looking at crontab -l then that sixth column is incorrect for the first line. –  Marco Ceppi Aug 25 '10 at 20:44
1  
the /etc/crontab file and a users personal crontab hasn't got anything to do with eachother. The crontab command edits the file /var/spool/cron/crontabs/$USER and doesn't use the same format! The systems crontab (/etc/crontab) needs the user parameter, but the crontab of a user is always executed as the user who owns it. –  Source Lab Aug 25 '10 at 21:19
    
@Source Lab exactly - that's why I'm curious if OP is possibly mixing the two formats up. –  Marco Ceppi Aug 25 '10 at 21:27
    
The mail subject makes it clear that it's the hourly line that is the source of the issue though. –  ℝaphink Aug 25 '10 at 21:30

Your /etc/crontab looks funny indeed. Every line should actually have a user column actually, which is the funniest part. For example, mine reads:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

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 )
#

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:

$ sudo apt-get install --reinstall --yes -o DPkg::Options::=--force-confmiss -o DPkg::Options::=--force-confnew cron

and see if it fixes the issue.

share|improve this answer

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:

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    * * *   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 )
#

This should resolve those email issues.

share|improve this answer
    
+1 Thanks for your help. –  grokus Aug 26 '10 at 0:01

Do it:

# crontab -r

And do NOT do it:

# crontab /etc/crontab

Instead, edits file /etc/crontab manually.

share|improve this answer

Your Answer

 
discard

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.