Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown    


Cron-jobs are maintenance jobs performed automaticly on your system every night, once a week or a month. Jobs like ¨logrotate¨ ( refreshing log files and zipping up old ones ) updatebd ( updating your ¨locate-search¨ database ) and a lot of other databases like the rpm database.
Cron comes from the Greek word chronos ( Time )

The program that takes care of this is the Cron-daemon. At a pre-selected time it starts doing the jobs that are to be done. Mostly between 3 and 5 at night because then it does not interrupt the users working hours. (if your computer is off at those times you´ll have to install ¨anacron¨ that picks up forgotten jobs the next time the computer boots ).

There are cron-jobs system wide, general rules that you should not be messing with. But you can add a series of user specific rules.

The schedule for cron is written in the /etc/crontab file.
Lets have a look at the system crontab:

$ cat /etc/crontab

Will show:

QUOTE (Text @ Screen)
# 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

The order of codes here is: minute, hour, day-of-month, month, day-of-week, user and command. The * means any value will do. So the first line tells it every ) 01 minutes, of 1 hour, of every day, of every week and every month ¨run-parts /etc/cron/hourly¨ The second line tells it to do the daily jobs at 4.02 hrs. The third line to do on day 0 the weekly job at 4.22. The last line to do every 1st of the month the monthly job at 4.42 !
If those times are very inconvenient you could change them to your preferences.

O.K so what is in /etc/cron.daily ?

$ cd /etc/cron.daily
$ ls

This will show you this:

0anacron - logrotate - makewhatis.cron - msec - rpm - tmpwatch

Those are all little scripts for the tasks to be done.
Just add your script ( backup ? ) and it will run with the other daily tasks. Shell or bash script it does not really matter.

Example: Have a look at the rpm script now that we are in the right directory:

$ cat rpm

will show you:

QUOTE (Text @ Screen)
rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}.rpm\n' 2>&1 | sort > /var/log/rpmpkgs

See ? . . . . . . #!/bin/sh on the 1st line and a "simple" command on the 2nd line !

Do explore a little and see what all the hourly to monthly tasks are about.

Sure for the ¨lazy´ ones there is also an X config version for cron you will find it in your KDE menu ( or whatever wm you are using ) Mandrakers look for;
Configuration --> Other --> X-Cron

I only did explain all this to you so you would better understand how things are done by the sofware you are running !


-- May 16 2003 ( Revised Dec 12 2005 ) --

Tips Linux Explorers   All Things Linux Forum   Great Linux Links   Hometown