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.
|
 |
05-17-2004, 09:37 AM
|
#1
|
Member
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133
Rep:
|
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
|
|
|
05-17-2004, 10:05 AM
|
#2
|
Senior Member
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380
Rep:
|
Can you explain what you are trying to do? The command date gives the date currently set by the bios.
|
|
|
05-17-2004, 10:17 AM
|
#3
|
Member
Registered: Dec 2003
Location: Johannesburg, South Africa
Distribution: Mandrake
Posts: 48
Rep:
|
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?
|
|
|
05-17-2004, 10:51 AM
|
#4
|
Member
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133
Original Poster
Rep:
|
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.
|
|
|
05-17-2004, 11:30 AM
|
#5
|
Senior Member
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380
Rep:
|
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.
|
|
|
05-17-2004, 12:32 PM
|
#6
|
Member
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133
Original Poster
Rep:
|
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.
|
|
|
05-17-2004, 01:06 PM
|
#7
|
Member
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221
Rep:
|
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.
|
|
|
05-18-2004, 05:35 AM
|
#8
|
Member
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133
Original Poster
Rep:
|
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.
|
|
|
06-10-2004, 02:52 PM
|
#9
|
Member
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720
Rep:
|
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
|
|
|
06-10-2004, 03:37 PM
|
#10
|
Member
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 08:55 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
|
|