 |
 |
Help me fix cron...
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Oz
Status:
Offline
|
|
Hi
Cron hasn't been working for me for a while now. I'm not sure what I did, or if some utility I installed did it for me, but now whenever one of OS X's maintenance scripts attempts to run I get the following email:
Subject: Cron <pat@dp800> root periodic daily
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin>
X-Cron-Env: <HOME=/Users/pat>
X-Cron-Env: <LOGNAME=pat>
X-Cron-Env: <USER=pat>
Date: Mon, 14 Jun 2004 03:15:01 +1000 (EST)
/bin/sh: line 1: root: command not found
I've replaced the crontab file with one from a fresh OS X install and repaired permissions to no avail. Help!
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: New York, NY
Status:
Offline
|
|
/bin/sh: line 1: root: command not found
This line appears to be stating that the command "root" has not been found.
Have you placed an entry in an actual user's cronfile that has a field before the command to execute specifying the desired user to run the command as?
There's two kinds of cron files on a system, the "System" cron file (/etc/crontab), and a cron file for each user. Only the system crontab (/etc/crontab) allows for the user field in the crontab entry for security reasons (file is only editable by root):
Code:
15 3 * * * root periodic daily
versus
Code:
15 3 * * * periodic daily
If you need to specify the user, add the entry to the system crontab. The field is not allowed in individual users' cron files because commands are executed as the user who owns the cron file for security reasons.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Oz
Status:
Offline
|
|
Yea it's from the system crontab. I don't have any users with their own, so I don't know what's going on.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: New York, NY
Status:
Offline
|
|
One thing I'm curious about :
X-Cron-Env: <LOGNAME=pat>
X-Cron-Env: <USER=pat>
The cron environment is for a specific user (and not root). I ran a test on my machine, adding a bogus job to /etc/crontab, and I received no mail to either the account cjones nor root. The system log confirms my bogus job tried to run.
So I looked in root's home directory, and sure enough, there's a .forward file forwarding all root's mail to /dev/null. I moved the file and tried again. root got the following mail for my bogus job in /etc/crontab:
Code:
From root@lapzilla.localhost Tue Jun 15 09:34:01 2004
Return-Path: <root@lapzilla.localhost>
X-Original-To: root@lapzilla.localhost
Delivered-To: root@lapzilla.localhost
Received: by lapzilla.localhost (Postfix, from userid 0)
id 0A5819F136; Tue, 15 Jun 2004 09:34:00 -0400 (EDT)
From: root@lapzilla.localhost (Cron Daemon)
To: root@lapzilla.localhost
Subject: Cron <root@lapzilla> blah
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin>
X-Cron-Env: <HOME=/var/root>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20040615133400.0A5819F136@lapzilla.localhost>
Date: Tue, 15 Jun 2004 09:34:00 -0400 (EDT)
Status: O
/bin/sh: line 1: blah: command not found
So root is the environment under which my /etc/crontab jobs are run. What are the ownerships and permissions of your /etc/crontab?
I still believe cron is trying to run the user field as a command, and I believe it's related to the fact that "pat" is the environment under which the crontab is being executed.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Oz
Status:
Offline
|
|
The permissions on my crontab are 444. How does cron determine who's account to run the crontab under?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: New York, NY
Status:
Offline
|
|
The permissions on my crontab are 444. How does cron determine who's account to run the crontab under?
Each job in /etc/crontab runs as the specified user - which is why the system crontab allows you to specify a user.
Sherlock Holmes would say.... 
1. System crontab allows user field, user crontabs do not
2. Cron error email states LOGNAME (which cannot be changed) is "pat", a user...
3. Cron error email states it cannot find the program "root", which would happen if the user field were placed in a user's crontab - it would be interpreted as the command to execute.
Have you checked the crontab for this user to make sure it's not trying to run this job? It really seems like the only explanation.
Can you post a long list (ls -al) of the directory "/var/cron/tabs"? Also post a long list of /etc/crontab, and finally, the output of the following command:
Code:
ps -aux | grep cron | grep -v grep
Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Status:
Offline
|
|
Here is what I suspect is happening...
There are a few ways to add a crontab to cron, once such way is to create a file, call it anything you want, such as 'mycrontab' then in the term to load it you type in crontab /path/to/mycrontab
Assuming you are not root, you can issue crontab -l and it will list the cron actions for the user you are logged in as in the terminal.
This method applies to all users EXCEPT root. Roots crontab is maintained by /etc/crontab However, this is not to say you can not load another one in with the same method as above, but this is wrong, root will accept the new crontab, but it will ignore the 'user' param and generate the error you are getting.
I suspect that at some point you or some other application added a crontab to root by accident, you could have been logged in as root and not known it, root will remember this forever. it will forever error as well. Perhaps you thought you were adding in some user crontab and were su'd as root.
Login/ssh as root, in the term, type whoami to make sure you are root, type crontab -r which will remove any crontabs that are NOT in /etc/crontab, this is how it should be, you NEVER need to load the root crontab like you do a user one, it reloads all by itself.
You should keep the .forward file in place, you can leave it to /dev/null or you can enter in a email address in the file and you will get reports about what the root crontab is up to.
You can also add a .forward to ~ (home) as well and any specific user crontab results will be emailed to you, assuming you have postfix set up to email. I know you should perhaps arguably not use a .forward for forwarding email in postfix, but for crontabs, it is relatively standard and a lot easier than adding in a forward in postfix.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Oz
Status:
Offline
|
|
I think I figured it out. Looks like somewhere along the line, the crontab in /etc/crontab was loaded for the user pat. As this crontab has the "who" field in it, cron was getting confused as it wasn't running under root. Issuing a crontab -l as pat showed that there was a crontab loaded, so i just did a crontab -r and got rid of it.
Thanks both of you for your help. Wouldn't have figured it out without your assistance.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: New York, NY
Status:
Offline
|
|
Roots crontab is maintained by /etc/crontab
Not true. Root has its own crontab. /etc/crontab is the "system" crontab. Type "crontab -e" as root to verify.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|