Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
<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.
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...
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.