5.10. Batch jobs

In administration tasks, it is usually necessary to execute certain tasks at regular intervals, either because it is necessary to program the tasks so that they take place when the machine is least being used or due to the periodic nature of the tasks that have to be performed.

There are various systems that allow us to set up a task schedule (planning task execution) for performing these tasks out-of-hours, such as periodic or programmed services:

25 6 * * * root test -e /usr/sbin/anacron || run-parts --report /etc/cron.daily 
47 6 * * 7 root test -e /usr/sbin/anacron || run-parts --report /etc/cron.weekly 
52 6 1 * * root test -e /usr/sbin/anacron || run-parts --report /etc/cron.monthl

where a series of tasks are programmed to execute: each day ("*" indicates 'whichever'), weekly (7th day of the week) or monthly (the 1st day of each month). Normally, the tasks will be executed with the crontab command, but the cron system assumes that the machine is always switched on, and if this is not the case, it is better to use anacron, which checks whether the task was performed when it was supposed to be or not, and if not, it executes the task. Each line in the preceding file is checked to ensure that the anacron command is there and the scripts associated to each action are executed; in this case, they are saved in directories assigned for this.

There may also be cron.allow or cron.deny files to limit who can (or cannot) put tasks in cron. Through the crontab command, a user may define tasks in the same format as we have seen before, which are usually saved in /var/spool/ cron/crontabs. In some cases, there is also a /etc/cron.d directory where we can place the tasks and they are treated as through they were an extension to the /etc/crontab file.