- Posted on
- • Software
at: Schedule one-time tasks
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
Scheduling One-Time Tasks in Linux with 'at'
In the world of Linux, efficiently scheduling tasks is key to managing workloads and automating processes. While cron
is widely known for handling repetitive tasks, Linux also provides a powerful utility for scheduling one-time jobs: at
. This tool allows you to schedule jobs that run at a specific time in the future, making it perfect for one-off tasks you don’t want to keep on your personal to-do list. Let's explore how to use at
, and how you can install it on different Linux distributions.
Installing at
Before you dive into scheduling tasks, you need to ensure that at
is installed on your system. The installation process varies depending on the package manager of your Linux distribution:
Debian/Ubuntu (using apt
)
For distributions like Debian, Ubuntu, and derivatives, install at
using apt
:
sudo apt update
sudo apt install at
Fedora (using dnf
)
If you're running a Fedora system, you'll use dnf
to install at
:
sudo dnf install at
openSUSE (using zypper
)
On openSUSE, at
can be installed using zypper
:
sudo zypper install at
Enabling the at
Service
After installation, the atd
service, which handles the execution of scheduled tasks, needs to be started and enabled to run at boot:
sudo systemctl enable --now atd
This command ensures that the at
daemon is active and running, ready to handle your scheduled tasks.
Using at
to Schedule Tasks
Scheduling tasks with at
is straightforward. Here is the basic syntax:
at [time] [day]
Where [time]
is when you want the job to run, and [day]
(if specified) tells at
which day the job should be executed.
Examples
Schedule a Job for Later Today:
To run a script at 4:30 PM today:
echo "/path/to/script.sh" | at 16:30
Schedule a Job for a Specific Date:
To backup your home directory on July 1st at 1:00 AM:
echo "tar czf /backup/home-$(date +%Y%m%d).tar.gz /home" | at 01:00 Jul 1
Using
at
Now + Time Increment:To reboot your system in 5 minutes:
echo "sudo reboot" | at now + 5 minutes
List and Remove Jobs
To see a list of scheduled tasks:
atq
To remove a specific job, use the job number provided by atq
:
atrm [job number]
Example:
atrm 3
Conclusion
The at
command is a reliable tool for scheduling one-time tasks, perfect for when you need to run jobs in the future but don't require the periodicity of cron
. By understanding how to use at
, you can more effectively manage automation and maintenance tasks on your Linux system, helping maintain order and efficiency.
Remember, regardless of your Linux flavor, at
is generally available and ready to help streamline your system management tasks. Happy scheduling!