[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

This is an old revision of the document!


Task Scheduling in Linux

Overview

This article discusses some tools used in a Linux system to schedule tasks to run automatically at specified time intervals or at any given point of time in the future. This primer will not cover these commands in-depth; this is just a brief introduction to using these commands. See the individual HOWTOS for each command for an in-depth look at all relevant options and configurations.

Some task-scheduling daemons used in Linux/UNIX are:

  • at – schedule one-time tasks for the future
  • cron – the periodic scheduler most commonly used
  • anacron – anachronistic cron; a periodic scheduler that doesn't rely on the system being left on 24×7

Using at

The at command allows a user to execute commands or scripts at a specified time (required) and date (optional). The commands can be entered via standard input, redirection, or file.

darkstar:~% at

Interactive at

Using the command at with standard input (keyboard) is a little more complicated than typing one line in at the prompt. The command uses an internal “sub-shell” to gather the required information. Once the command information entry is complete, Ctrl+D (EOT) will signify entry completion. The -m flag specifies a mail message will be sent to the user when the job is finished, regardless if any output was created.

darkstar:~% at 12:01 -m
warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh
at> ./my_script.sh
at> <EOT>
job 4 at 2015-06-22 12:01 
darkstar:~% 

=====Using cron=====

**//cron//** is a daemon that runs tasks in the background at specific times. For example, if you want to automate downloads of patches on a specific day (Monday), date (2 July), or time (1300), **//cron//** will allow you to set this up in a variety of ways. The flexibility inherent in **//cron//** can allow administrators and power users to automate repetitive tasks, such as creating backups and system maintenance.

**//cron//** is usually configured using a //crontab// file. The following command will open your user account //crontab// file: 

<code>
darkstar:~% crontab -e

To edit the system-level crontab, first log into the root account:

darkstar:~# crontab -e

If your system has sudo installed, type in:

darkstar:~% sudo crontab -e 

The crontab file syntax is:

minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6) command

Using an asterisk in any placeholder location, will match any value. For example, the following will run example_script.sh at noon (1200) everyday during the first three months of the year:

#For more information see the manual pages of crontab(5) and cron(8)
#
# min hr day month weekday command
#
#
 
0 11 * 1-3 * /home/user/example_script.sh

Using anacron

anacron is not installed in Slackware by default.1)
The links in red are to non-existent articles.

If you are experienced with those tools, please feel free to write the articles.

Sources

1)
See Slackbuilds.org for more information on anacron on Slackware
 howtos:general_admin:task_scheduling ()