![]() |
cron /bin/sh: root: command not found
I thoroughly understand the cron process and how to right cront tasks but I do not understand why the tasks always fail with:
cron /bin/sh: root: command not found Its the user "root" that is failing. If you remove the user field the script runs fine - but that makes no sense. For example - from the system crontab: 51 9 * * * root periodic daily This is a straight up stock entry - should not fail. But whenever it attempts to run - instead of completing successefully it always generates the : cron /bin/sh: root: command not found Anybody have any suggestions? |
I don't know about BSD. But in Linux crontab i don't recall any user field. The error message also suggests that cron expects the command to execute in the sixth field.
Try: man crontab -S 5 And see what it says about the fields cron expects. I would check myself, but I'm not anywhere near an OS X machine. (Which is a bit painful for an OS X junkie like myself. =) |
Exactly - I use a Linux box on my LAN for some stuff and it does not have a USER field. But all the stock - preinstalled OS X crontab's do.
|
I agree, it makes little sense. You haven't accidently installed a more Linux-like cron that happens to be run instead of the OS X one?
|
not that I know of...wonder of Fink has its own cron....I'll have to check into that - sometimes /sw/bin stuff can get in the way of legitimate binaries...
|
Dunno if this is your problem, but the distinction you're butting up against here is (I think) present in all cron implementations. Users don't get to specify the user (so there's no user field in users' crontabs) but the root user (being the great superstar that he or she is) gets to pick the user that the job runs under, and hence has a different format for the crontab. In particular, they get one extra field to fill in.
So my guess is that you're editing your own crontab in such a manner that the cron daemon thinks you want to execute the "root" command. You'll have to edit root's crontab (ie /etc/crontab) if you're trying to get a command to run "as" root. Or just rip out the root and have the next command in that line execute as your poor old mortal self. Then again I might be on drugs. Cheers, Paul |
note that the format of /etc/crontab and users % crontab -l are differrent by the user column...
Code:
$ less /etc/crontab | fold -sw 60paul may still be on drugs. |
pmccann - actually its running inthe system crontab - which does require root capabilities
mervTormel - very interesting! What should I ascertain from that info? |
Quote:
|
try this to examine the tabulation of your crontab file...
Code:
$ cat -vt /etc/crontab |
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin HOME=/var/log 19^I10^I*^I*^I*^Iroot^Iperiodic daily 0^I3^I*^I*^I6^Iroot^Iperiodic weekly 0^I3^I1^I*^I*^Iroot^Iperiodic monthly 15^I3^I*^I*^I*^Iroot^I/usr/local/bin/psync -d /Volumes/HD1 /Volumes/HD2 |
hmm, why is etc in the path? where is periodic?
what happens if you remove etc: from path and put full path to periodic for the commands |
Not sure why etc is in path.
Already tried including full path to periodic: /usr/sbin/periodic - still no go. Removing /etc from path has no effect. |
hmm, still haven't seen evidence that the cron entries you are showing us are from your /etc/crontab file.
is that the case? or are you showing us the results of % sudo crontab -u root -l ? |
straight out of pico /etc/crontab
|
OK, so what's periodic? : I don't have no stinkin' periodic.
I guess it's just an "all-in-one" that takes daily/weekly/monthly as a parameter, but where's it from and what's in it. The 'root' aspect might be a red herring; could it be that periodic can't be found/executed? Is there maybe a #! line at the start of periodic that's inappropriate for osx? Thus endeth this portion of the interrogation. Cheers, Paul |
okay. then what does
% sudo crontab -u root -l say? does your psync work at 3:15 am? where did you get this /etc/crontab? it is not the OSX dist'd one. where is periodic from? it is not OSX dist'd, and i'm surprised that it's in /usr/sbin/ looks like a FreeBSD dist of periodic ? man, there's a lot of bug reports about that thing. anyhow... |
Periodic is simply a shell script that looks for a folder of scripts and runs the contents of that folder. Common on Linux setups (although on Linux I believe it is called "run-parts") - so instead of calling the daily maintenace type stuff individually - you just call Periodic - which in turn looks for a specific folder. Place the other scripts you want to run within that folder and they are exe by the Periodic script.
#!/bin/sh - # # $FreeBSD: src/usr.sbin/periodic/periodic.sh,v 1.9.2.7 2000/11/26 06:06:18 kris Exp $ # # Run nightly periodic scripts # # usage: periodic { daily | weekly | monthly } - run standard periodic scripts # periodic /absolute/path/to/directory - run periodic scripts in dir |
Actually this is/will be standard dist OSX crontab - I can say nothing more than that ...
Strangely enough the psync DOES work....and it has the root user listed. But the root problem has plagued me for some time. This is just an example today...I finally got around to posting about it. Quote:
|
Umm... these are my guesses:
[list=1][*]Is #!/bin/sh - (with the - sign) valid for a shell script?[*]Is periodic executable? (chmod 755)[/list=1] |
#!/bin/sh -
does work - although I do not know what the - is for. periodic is set: -r-xr-xr-x 1 root wheel 2875 Jul 14 16:57 /usr/sbin/periodic Also - I manually called: periodic daily (as root) and that worked fine I also individually ran the two script that periodic daily runs and they both ran fine. Very odd indeed....I thought for sure this was an easy one....for someone with more knowledge that me in shell scripting. |
how about pointing us to where you got your periodic from and we could try to duplicate your problem? it is a head scratcher.
|
bluehz,
From what I know, /etc/crontab is not the root users crontab, and thus behaves a little differently than a user's crontab. When using /etc/crontab, you have to specify the user the operation should run as. It should then honor the variables defined in the config file. Have you tried to make an entry something like: 51 *9 * * * root /usr/sbin/periodic -u xxx.xxx.x.x Also, if you do crontab /etc/crontab and you fill roots' mailbox with "not found messages", the thing to do then, would be to login as root and crontab -r should do the trick. Cheers... |
This is an old thread, but for those who may stumble on this:
/etc/crontab is different from user crontabs. Former has a field to specify the username to run command as, latter does not. Now, even root has a "user" crontab. This is different from /etc/crontab. It looks like the original poster had accidentally run "crontab /etc/crontab" as root. In other words, made /etc/crontab as root user's crontab. Because latter cannot specify a user, it was treat as command and hence the "sh: root: cannot find command" error message. The solution is to remove this unwanted crontab entry. It should be in /var/spool/crontab/root (or similar -- check "man cron" to find the directory) and remove the crontab created for root. And DO NOT run the command "crontab /etc/crontab" -- that'll make a copy of /etc/crontab as the current user crontab, and that'll never work as /etc/crontab uses a different format than user crontab. ~talkative |
| All times are GMT -5. The time now is 06:12 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.