Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
|
11-09-2007, 10:29 AM
|
#1
|
Member
Registered: Aug 2007
Posts: 37
Rep:
|
Cron job help
Hi everyone,
I'm a relative new comer to Linux, but I'm trying to learn how to use cron jobs. The problem I'm having is that I can't seem to get a job to run at all. I'm running Red Hat Enterprise Linux 4 and I've entered the command:
crontab -e
to install a new job, and then I create the following line in vi:
52 11 * * * root ls /proc >> /home/ma15032/Crontest/log
So all I'm trying to do is write the contents of the /proc directory to the log file at 11:52 this morning. It doesn't look like the job starts at all.
Can anyone offer a suggestion as to why this is?
Thanks,
Tejama
P.S. I've also checked the cron logs and there is no entry at all around the time I scheduled the job to run.
|
|
|
11-09-2007, 10:50 AM
|
#2
|
Member
Registered: Oct 2007
Distribution: rhel, fedora, gentoo, ubuntu, freebsd
Posts: 104
Rep:
|
If you use "crontab -e" you're editing your user crontab (for the user you run it as ... probably root).
If you are editing your user crontab, you don't specify the user it's being run as.
If you're editing the system crontab (/etc/crontab), you would specify the user it's being run as (ie: do what you did). In crontab -e, lose the "root" and you should be a bit more likely to have things work.
|
|
|
11-09-2007, 11:21 AM
|
#3
|
Member
Registered: Aug 2007
Posts: 37
Original Poster
Rep:
|
@complich8: Thanks for clearing up the use of "crontab -e". Unfortunately, I followed your suggestion and I'm still not seeing any indication that the job is even trying to run.
|
|
|
11-09-2007, 11:33 AM
|
#4
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
What does your revised crontab look like?
Does /home/ma15032/Crontest/ exist? Does 'ls /proc >> /home/ma15032/Crontest/log' work when run directly from the command line?
|
|
|
11-09-2007, 11:38 AM
|
#5
|
Member
Registered: Aug 2007
Posts: 37
Original Poster
Rep:
|
/etc/crontab looks like this:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
54 12 * * * root ls /proc >> /home/ma12117/Crontest/log
The directory does exist and the "log" file gets created when I run it in a terminal. This is a fresh install of RH Enterprise 4, is there anything I would have need to have done to enable cron jobs to run? I've made sure the crond daemon is running, other than that I can't think of anything.
|
|
|
11-09-2007, 11:43 AM
|
#6
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
Check root's mail to see if cron is sending error email (at least it will be an indication the job got run).
Failing that, run a simple command in the crontab, e.g. /bin/echo 'From cron with love'
Is that at least getting to root's mail?
Does /etc/cron.allow or /etc/cron.deny exist?
Do you see any selinux cron-related messages in /var/log/mesages?
Finally, I know you already checked, but check again that the daemon is running:
ps -ef | grep crond
|
|
|
11-09-2007, 11:49 AM
|
#7
|
Member
Registered: Aug 2007
Posts: 37
Original Poster
Rep:
|
@anomie: I'm seeing no error mail at all. The mailbox is empty.
When I run ps -ef | grep crond, this is returned:
root 5645 1 0 11:36 ? 00:00:00 crond
So I'm guessing cron is running fine.
In the /var/log/messages directory, the only references to cron is when I've restarted the daemon.
|
|
|
11-09-2007, 11:53 AM
|
#8
|
Member
Registered: Aug 2007
Posts: 37
Original Poster
Rep:
|
Oh, cron.allow doesn't exist and cron.deny is empty.
|
|
|
11-09-2007, 12:04 PM
|
#9
|
Member
Registered: Aug 2007
Posts: 37
Original Poster
Rep:
|
Ok...so I logged onto an ESX server we have in the office and I created a cron job that worked exactly as it should. So I'm very confident it's not my syntax, but rather some config issue with Red Hat. Any suggestions?
|
|
|
11-09-2007, 12:14 PM
|
#10
|
Member
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324
Rep:
|
^ If you have send mail I can tell you how tested cron.
Code:
suffix=$(date)
echo $suffix x1A | mail -s "Say hello to my little friend " your-email@something.com
Add this line to /etc/crontab
restart crontab
Code:
0,10,20,30,40,50 * * * root /path/to/code
Last edited by knockout_artist; 11-09-2007 at 12:20 PM.
|
|
|
11-09-2007, 12:15 PM
|
#11
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
I don't have a RHEL4 box to view at the moment. For the hell of it, modify your /etc/crontab again (to run the command, say, 10 minutes in the future) and then run:
# restorecon /etc/crontab /usr/sbin/crond
And then:
# /etc/init.d/crond restart
Any luck? If not, I am out of ideas for the moment.
|
|
|
11-09-2007, 12:23 PM
|
#12
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Why edit the system crontab file?! When you run 'crontab -e' a per-user crontab file should be installed under /var/spool/cron, even for root. And if the cron daemon is running, it should be executed properly.
|
|
|
11-09-2007, 12:29 PM
|
#13
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
Quote:
Originally Posted by colucix
Why edit the system crontab file?!
|
While it may be more "proper" form (depending on how you like to do things) to edit a user crontab or simply add a script to one of the /etc/cron.hourly||daily||weekly||monthly directories, I don't see what that has to do with his problem.
From cron(8):
Quote:
Cron searches /var/spool/cron for crontab files which are named after
accounts in /etc/passwd; crontabs found are loaded into memory. Cron
also searches for /etc/crontab and the files in the /etc/cron.d direc-
tory, which are in a different format (see crontab(5)). Cron then
wakes up every minute, examining all stored crontabs, checking each
command to see if it should be run in the current minute.
|
Cron should still find the entry in /etc/crontab and execute it. Something is borked.
|
|
|
11-09-2007, 12:31 PM
|
#14
|
Member
Registered: Aug 2007
Posts: 37
Original Poster
Rep:
|
@anomie: We have a winner! Seems like cron jobs are now running properly. Now I'm off to figure out what you had me do! lol
In the meantime, thanks to all for the help! Great to have this type of support.
|
|
|
11-09-2007, 12:32 PM
|
#15
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
The command I mentioned restores the default selinux context. Glad it's fixed.
|
|
|
All times are GMT -5. The time now is 05:58 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|