8.1 About Automating Tasks

You can use automated tasks to perform periodic backups, monitor the system, run custom scripts, and other administrative tasks.

The cron and anacron utilities allow you to schedule the execution of recurring tasks (jobs) according to a combination of the time, day of the month, month, day of the week, and week. cron allows you to schedule jobs to run as often as every minute. If the system is down when a job is scheduled, cron does not run the job when the system restarts. anacron allows you to schedule a system job to run only once per day. However, if a scheduled job has not been run, that job runs when the system restarts. anacron is mainly intended for use on laptop computers.

You do not usually need to run cron and anacron directly. The crond daemon executes scheduled tasks on behalf of cron and it starts anacron once every hour. crond looks in /etc/crontab or in files in /etc/cron.d for system cron job definitions, and /var/spool/cron for cron job definitions belonging to users. crond checks each job definition to see whether it should run in the current minute. If a job is scheduled for execution, crond runs it as the owner of the job definition file or, for system cron jobs, the user specified in the job definition (if any).

crond runs the 0anacron script in the /etc/cron.hourly directory as root once per hour according to the schedule in /etc/cron.d/0hourly. If anacron is not already running and the system is connected to mains and not battery power, crond starts anacron.

anacron runs the scripts in the /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly directories as root once per day, week or month, according to the job definitions that are scheduled in /etc/anacrontab.