Command AT
April 16, 2025Need to run a job once at a specific time? Sounds like a cron job. But cron is for repeated periodic execution. To run a task once at a predefined time, use the "at" command. In this article, I'll teach you how to use the "at" command.
Installation
As is standard with Linux distributions, all applications are available as a ready-made package for that Linux distribution. Similarly, the "at" command is commonly available in your distribution's repository.
In the Mageia distribution, you can install the "at" program with the following command:
urpmi at
In the Debian distribution, you install the "at" program with the following command:
apt-get install at
The "at
" command runs in the background, as a daemon, and runs jobs under the user who scheduled the job.
Therefore, you need to start the daemon and enable the "at" daemon to start after the computer boots.
To do this, use the command:
systemctl enable etc && systemctl start etc
Command at
The "at
" command is used to schedule a command or script to run once at a specific time in
future.
Basic Usage
Interactive mode
at 16:00
Then type the commands and exit by typing Ctrl+D
.
Scheduling a job
echo "ls -l /home/user" | at 14:30
Executes the command "ls -l /home/user
" at 14:30 on the same day.
Schedule the computer to shut down on a specific date
echo "reboot" | at 23:59 31.12.2025
Show scheduled tasks
If you want to check which user scheduled what for what time, use the following command, which will list the scheduled jobs with their start time:
atq
Alternatively, you can use
at -l
Cancel a Scheduled Job
You can decide that you want to cancel a task. You can cancel a task that is scheduled. To delete a scheduled task, use the command:
atrm <task number>
You can get the job number from the atq
statement.
Special times
at now + 1 hour
→ Runs the command in 1 hour.at now + 30 minutes
→ Executes the command in 30 minutes.at midnight
→ Runs the job at midnight.at teatime
→ Runs the job at 4:00 pm.
Video tutorial
Practical video demonstration of how to use the AT command:
Commands in file
You don't have to enter commands manually, but you can write what you need to execute to a file. And then pass that file to the "at" program. Especially if you have a complex command or know you will want to run it sometime in the future, it is a good idea to write it down and save time afterwards.
You then pass your script to the "at" program as follows:
at -f config.at 13:00 2024-04-05
Beware of the default shell
The "at
" command allows you to run tasks at a specific time, but it is important to note that these tasks
are by default run in a non-interactive shell (usually /bin/sh
or another default system shell). This
can cause problems if the user expects their preferred shell to be used (e.g. bash
,
zsh
) or that certain environment variables will be available.
Why specifically this needs to be considered:
- A shell other than your interactive - For example, if you use
bash
but "at
" triggers/bin/sh
, then some constructs for example([ ... ]]
,declare
,source
may not work. - Missing environment variables - A task run via
at
does not have the same environment as your interactive shell. For example, your custom aliases, functions, or modified$PATH
. - Need to explicitly specify a shell - If you want the
at
task to run in a specific shell, you must explicitly specify it.
Therefore, I recommend to always specify which shell you want to run your commands in, so that you don't have to wonder why your script behaves differently when you run it manually than when you run it with the "at" program.
Automate
The "at" program is one of many programs, that will make your job easier if you're using a powerful tool like the Linux operating system on your servers. Use tools that make your job easier and automate tasks that you would otherwise have to do manually. This will save you a lot of time and therefore money.
Articles on a similar topic
Docker build multiarch image
VMware vs Proxmox: performance comparison
GitLab CI/CD: test automation and application deployment
Migrating VPS from VMware to Proxmox
VMware licensing change
Running Microsoft SQL Server on Linux
Backup: the Proxmox Backup Server
Linux as a router and firewall
How to upload a docker image to the Docker Registry
Linux: logical volume management
Linux Software RAID
Running a web application behind a proxy
Mailbox migration
Docker multistage build
Backing up your data by turning on your computer
Podman
Importing Windows into Proxmox virtualization
Docker and PHP mail
Proxmox virtualization
Docker and Cron
Lenovo ThinkPad X1 Carbon: LTE modem EM7544 commissioning
Yocto Project: Build custom operating system for embedded devices
Preparing a Linux server to run a web application in Python
How to address poor file share performance in Docker
How to get started using Docker correctly
Installing Linux on a dedicated HPE ProLiant DL320e server
How to stress test a web application
Why use the JFS filesystem
How to boot from a 4TB drive with GTP using UEFI
Btrfs file system
Raspberry PI
WINE - running Windous programs under Linux
GNU/Linux operating system
Newsletter
If you are interested in receiving occasional news by email.
You can register by filling in your email
news subscription.
+