Linux - NewbieThis 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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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;
##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
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;
#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.
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?
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
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.