LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 11-09-2007, 09:29 AM   #1
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Rep: Reputation: 15
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.
 
Old 11-09-2007, 09:50 AM   #2
complich8
Member
 
Registered: Oct 2007
Distribution: rhel, fedora, gentoo, ubuntu, freebsd
Posts: 104

Rep: Reputation: 15
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.
 
Old 11-09-2007, 10:21 AM   #3
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Original Poster
Rep: Reputation: 15
@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.
 
Old 11-09-2007, 10:33 AM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
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?
 
Old 11-09-2007, 10:38 AM   #5
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Original Poster
Rep: Reputation: 15
/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.
 
Old 11-09-2007, 10:43 AM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
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
 
Old 11-09-2007, 10:49 AM   #7
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Original Poster
Rep: Reputation: 15
@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.
 
Old 11-09-2007, 10:53 AM   #8
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Original Poster
Rep: Reputation: 15
Oh, cron.allow doesn't exist and cron.deny is empty.
 
Old 11-09-2007, 11:04 AM   #9
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Original Poster
Rep: Reputation: 15
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?
 
Old 11-09-2007, 11:14 AM   #10
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
^ 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 11:20 AM.
 
Old 11-09-2007, 11:15 AM   #11
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
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.
 
Old 11-09-2007, 11:23 AM   #12
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.
 
Old 11-09-2007, 11:29 AM   #13
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
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.
 
Old 11-09-2007, 11:31 AM   #14
tejama
LQ Newbie
 
Registered: Aug 2007
Posts: 28

Original Poster
Rep: Reputation: 15
@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.
 
Old 11-09-2007, 11:32 AM   #15
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
The command I mentioned restores the default selinux context. Glad it's fixed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron job somsahi Linux - Software 2 10-24-2006 05:40 AM
Cron Job petenyce Linux - Newbie 5 10-11-2005 04:03 PM
cron job wbatzle Linux - Newbie 2 07-12-2005 04:19 PM
cron job sanjith11 Linux - General 5 07-14-2004 01:06 PM


All times are GMT -5. The time now is 01:56 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration