LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   /bin/bash: root: command not found (https://www.linuxquestions.org/questions/red-hat-31/bin-bash-root-command-not-found-507193/)

pridefc 12-03-2006 04:33 PM

/bin/bash: root: command not found
 
Hello,

I edited /etc/crontab directly and added
00 10 * * * root /bin/script.sh

Since then, I get "/bin/bash: root: comand not found"
but the command runs fine.

So I removed the "root" from the line since it was thinking that "root" was the command and was trying to run it.
00 10 * * * /bin/script.sh

then restarted crond "/etc/init.d/crond restart" so that it would re-read the modified /etc/crontab.

However, I still get "/bin/bash: root: command not found" although I removed the "root" from the line.
It must not be reading the new /etc/crontab file.
Is there a way to make it read the modified crontab?
I must be doing something wrong.

Thanks.

Simon Bridge 12-03-2006 04:56 PM

How did you edit crontab? (i.e. vi, emacs, gedit, crontab -e ... ?)
Quote:

[snip]it was thinking that "root" was the command and was trying to run it.
Indeed. From the cron man page:
Code:

The sixth field of a line in a crontab file is a string that
    is  executed  by the shell at the specified times.

... if you want it executed with root privaledges, then it should be in the root user's crontab.

So the next question is: are you sure you edited the right one?

mikemrh9 12-03-2006 04:57 PM

I think that you were right the first time - the name 'root' should be in the /etc/crontab file.

The problem could be the syntax for the time for the command to run. I assume that you want it to run at 10:00 each day, and not on the 10th of the month?

Try putting 0 instead of 00 for the first digit. The format should be based on the following:

minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)



ie try putting:

0 10 * * * root /bin/script.sh

If you have 00 for the minute field, that could possibly be interpreted as 0 0 10 * * for the time, making 'root' the first command, hence the 'command not found' message.

Simon Bridge 12-03-2006 06:57 PM

Quote:

Originally Posted by mikemrh9
the name 'root' should be in the /etc/crontab

<slaps forehead> Of course! This is the systemwide crontab file and I'm an idiot :) Yeah - unlike the regular crontab, the system wide one has a "user" feild.

pridefc 12-05-2006 11:00 PM

Thanks guys.
But if you have one in /etc/crontab and one in crontab -l,
which one takes effect if they're different or the same?
Does /etc/crontab stay dormant until you load it?
It seems it's running both of them, the one in /etc/crontab and the one that shows up when you do crontab -l.
Kind of confusing...

chrism01 12-12-2006 07:09 PM

It runs both.
The system is that /etc/crontab is (usually) for admin tasks eg backup and the user's individual crontabs are for their own progs (whatever).
ALL crontabs will be processed by the cron daemon, so do not duplicate instructions across these files.
Incidentally, cron re-reads crontab files every minute, so restart is not needed unless cron dies/hangs (very rare).
It also triggers a re-read if you use crontab -e (dedicated crontab editor) instead of eg vim.
crontab -e is really for non-root users, they are not supposed to edit their files directly.


All times are GMT -5. The time now is 12:34 PM.