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:
nohup is perhaps the simplest command used by users, as it permits the execution of a non-interactive task once they have logged out from their account. Normally, when users log out, they lose their processes; nohup allows them to leave the processes executing even though the user has logged out.
at permits us to launch a task for later, programming the determined point in time at which we wish for it to start, specifying the time (hh:mm) and date, or specifying whether it will be today or tomorrow. Examples:
at 10pm task
to perform the task at ten o'clock at night.
at 2am tomorrow task
to perform the task at two o'clock in the morning.
cron: it permits us to establish a list of tasks that will be performed with the corresponding programming; this configuration is saved in /etc/crontab; specifically, in each entry in this file, we have: hour and minutes at which the task will be performed, which day of the month, which month, which day of the week, along with which element (which might be a task or a directory where the tasks that are to be executed are located). For example, the standard content is similar to:
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.