LinuxQuestions.org
Review your favorite Linux distribution.
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 05-17-2004, 10:37 AM   #1
carlmarshall
Member
 
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133

Rep: Reputation: 16
Unable to get crontab working


Using Mandrake 10.0 community (i586)

Just tried setting up a crontab in /etc/crontab (as root)

here's the file:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root nice -n 19 run-parts /etc/cron.hourly
02 4 * * * root nice -n 19 run-parts /etc/cron.daily
22 4 * * 0 root nice -n 19 run-parts /etc/cron.weekly
42 4 1 * * root nice -n 19 run-parts /etc/cron.monthly
*/5 * * * * root date >> /root/date

The original entries (run-parts) work fine, but the last entry (which works OK from the command line) never gets run (or it fails to complete).

I've reloaded with "crontab crontab" but still to no effect.

Any ideas?

Carl
 
Old 05-17-2004, 11:05 AM   #2
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
Can you explain what you are trying to do? The command date gives the date currently set by the bios.
 
Old 05-17-2004, 11:17 AM   #3
andredude
Member
 
Registered: Dec 2003
Location: Johannesburg, South Africa
Distribution: Mandrake
Posts: 48

Rep: Reputation: 15
why are you trying to set up crontab? it should already be running, just go "crontab -e" and put the jobs you want to run in there?
 
Old 05-17-2004, 11:51 AM   #4
carlmarshall
Member
 
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133

Original Poster
Rep: Reputation: 16
TigerOC,

That's just a test command which should work doing exactly as you say. I've not included the real one as the test one isn't working.

andredude,

I created the crontab in exactly the manner you describe. The original entries (run-parts) are OK, the last line never gets run.

I've checked the /var/log/cron entries. No errors, no warnings, and the info file never mentions the last line.

Heeeelp.
 
Old 05-17-2004, 12:30 PM   #5
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
Its probably worth looking at cron and what it does. It is intended to run shell scripts at defined times. I have a couple running on my system so I'll use one as an example.
I want to keep my /home partition backed-up on an hourly basis to a non-mounted hard drive (hda6). I use rsync to do this so I created the following script;

#!/bin/bash
##mount /dev/hda6 on /mnt
mount -t ext3 /dev/hda6 /mnt
##backup files to hda6
rsync --delete-after -avH /home/ /mnt/backup/home > /var/log/backup.log
##umount hda6
umount /dev/hda6

The script is self explanatory. The script is made executable. There was no cron.hourly on my system so I created it and put the script in. I then edited /etc/crontab and inserted the line;

10 * * * * root /etc/cron.hourly/backup

at 10 past each hour /home is backed up and the output is sent to /var/log/backup.log

I think the problem you have is that the date command has no output. Make a script;

#!/bin/bash
#send date to text file
date > /home/your_usr_name/date.txt

make it executable chmod 700 ./date put it into one of the cron.* dirs and edit crontab as above.
 
Old 05-17-2004, 01:32 PM   #6
carlmarshall
Member
 
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133

Original Poster
Rep: Reputation: 16
Thanks for that TigerOC

The date >> /root/date command does have an output, but ....

I tried the method of creating an executable script, no joy.

In the end i've got it working though, here's how:

The line "crontab crontab" seems to copy the /etc/crontab file into the user's own crontab file. So when I did a "crontab -e" I had the "run-parts" bit in there. Leaving that produced an error email from crond stating that the command "root nice -n 19 run-parts /etc/cron.hourly" could not be found. Not suprising as a user crontab has no user element, only the command.

I therefore removed the "run-parts" section from the crontab -e and also removed the "root" reference. Still no good.

In desperation, I did a crontab -e and deleted the lot.

Adding the required line into the /etc/crontab file (as the first line rather than the usual last one) it worked! - Whoppee!

Just in case anyone knows:

Can root have a user crontab?
If so, is this a problem?
Is there an issue in adding lines to /etc/crontab after the run-parts?

Cheers,

Carl.
 
Old 05-17-2004, 02:06 PM   #7
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
Posts: 218

Rep: Reputation: 24
Hi Carlmarshall -- Cron is not very smart about paths. I just checked
in my debian system nice is really /usr/bin/nice but date is /bin/date. (Found that out with which nice and which date). The general advice
in cron scripts is to explicitly code the path to each command.
The fact that "it works when I don't run it through cron" doesn't cut
any ice. Cron's paths are different. Let me know if this helps.
 
Old 05-18-2004, 06:35 AM   #8
carlmarshall
Member
 
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133

Original Poster
Rep: Reputation: 16
Thanks for the reply pcardout, however that's not the issue as both date and nice are now working once I got rid of the root user crontab, and the paths are specified in the path= section.

Carl.
 
Old 06-10-2004, 03:52 PM   #9
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
Hey

I'm trying to set up a my cron daemon, however, I have no /etc/crontab

Should I just make one? If so, what type of file is it?

Hamish
 
Old 06-10-2004, 04:37 PM   #10
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
Posts: 218

Rep: Reputation: 24
Editing crontab

Use crontab command

crontab -ujohn -l lists the crontab file for user john
crontab -ujohn -e edits it (creates it if needed)

If john doesn't have rights you have to do this, create a file
/etc/cron.allow (with an ordinary editor) and put the name john in it.
 
  


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
crontab not working durgap Linux - General 6 09-01-2005 03:38 PM
Users unable to use crontab unless in /etc/shadow atnan Linux - General 2 05-04-2005 12:43 AM
crontab nor working navaladi Mandriva 11 01-17-2005 07:58 AM
crontab not working subaruwrx Linux - Newbie 8 08-17-2004 10:12 PM
Crontab not working Neorio *BSD 1 12-02-2003 08:34 PM


All times are GMT -5. The time now is 04:03 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration