The Linux/Unix Command: atd

Manage your Linux task scheduling system

Development Team Cooperating In Their Office.

vgajic / Getty Images

Have you ever needed to run a command or even a complete script at a certain date and time. Sure, if you need to run something in a recurring manner, you have cron, but what happens when you need to only run it once? That's where atd comes in.

Atd is actually the 'at' daemon that runs in the background of your Linux system and executes commands at a specific time. You can schedule both one-off commands and scripts easily with atd, and there's no need to worry about them running a second time or the need to be present to run them.

Installing ATD

To start, you'll probably need to install atd. You can do that easily enough with your distribution's package manager.

Debian/Ubuntu/Mint

sudo apt install at

Fedora

sudo dnf install at

CentOS/RHEL

sudo yum install at

OpenSUSE

sudo zypper install at

Arch Linux/Manjaro

sudo pacman -S at

Starting and Enabling ATD

Before you can work with atd, you need to start and enable it, since it is a daemon. You can do that easily enough with systemd.

sudo systemctl start atd
sudo systemctl enable atd

Using ATD

The atd command lets you manage the scheduling daemon, while the at command lets you actually schedule, run, and manage jobs. More often than not, you're going to be working with at, rather than atd.

The first thing you probably want to do is set the limiting load factor. Essentially, this will determine how much of your system's power can be used by jobs scheduled with at. The '-l' flag followed by a number will do it. Since, most computers have multiple cores and threads. A good number to use is the number of processing threads on your computer minus one. So, on a quad-core computer with one thread per core, you'd use:

sudo atd -l 3

Next, it's a good idea to set the minimum batch interval for your 'at' jobs. This is the minimum amount of time between the start of two jobs, and you set it with the '-b' flag followed by a number of seconds. Again, this number should be determined by the amount of processing power and memory that your system has. The default is 60 seconds. That's fair, but a quad core system can easily get away with setting it to 30, in most situations. If your computer has more power, feel free to experiment and lower the number even more.

sudo atd -b 30

These are the most common commands that you'd use in configuring atd. For more detailed information, refer to the full manual below.

ATD Command Manual

Below you'll find the full technical breakdown of atd on Linux systems.

Synopsis

atd [-l load_avg] [-b batch_interval] [-d] [-s]  

Description

atd runs jobs queued by at.

Options

-l

Specifies a limiting load factor, over which batch jobs should not be run, instead of the compile-time choice of 0.8. For an SMP system with n CPUs, you will probably want to set this higher than n-1.

-b

Specify the minimum interval in seconds between the start of two batch jobs (60 default).

-d

Debug; print error messages to standard error instead of using syslog.

-s

Process the at/batch queue only once. This is primarily of use for compatibility with old versions of atatd -s is equivalent to the old atrun command. A script invoking atd -s is installed as /usr/sbin/atrun for backward compatibility.

Warning

atd won't work if its spool directory is mounted via NFS even if no_root_squash is set.  

Use the man command (% man) to see how a command is used on your particular computer.