
{{ $('Map tags to IDs').item.json.title }}
How to Use at Command for One-Time Jobs
The at
command in Linux is used to schedule one-time tasks to be executed at a specific time in the future. It is particularly useful for automating tasks that need to be run just once at a defined time. This tutorial will walk you through the basic usage of the at
command to schedule jobs effectively.
1. Installing at
Most Linux distributions come with the at
command pre-installed. You can check if it is available by running:
at -V
If it is not installed, you can install it using:
- For Ubuntu:
sudo apt update sudo apt install at
- For CentOS:
sudo yum install at
2. Starting the atd Service
The at
command requires the atd
daemon to run. Ensure it is active with:
sudo systemctl start atd
To enable it to start on boot:
sudo systemctl enable atd
3. Scheduling a One-Time Job
To schedule a job with at
, use the following syntax:
echo "command" | at time
For example, to run a script at 3:15 PM, you would run:
echo "bash /path/to/script.sh" | at 15:15
3.1. Specifying Dates and Times
You can specify the time using various formats:
- Absolute time:
at 14:00
- Relative time:
at now + 1 hour
- Specific date:
at 10:00 2022-10-01
4. Listing Scheduled Jobs
To view all scheduled jobs for your user, execute:
atq
This will display a list of pending jobs along with their job ID.
5. Removing Scheduled Jobs
If you need to cancel a scheduled job, use the atrm
command with the job ID:
atrm job_id
Replace job_id
with the actual ID you wish to remove. You can find this ID in the atq
output.
6. Conclusion
By following this tutorial, you have learned how to use the at
command for scheduling one-time jobs in Linux. Automating tasks with at
can help improve productivity and ensure that important jobs run at the correct times. Continue to explore advanced features to maximize the effectiveness of scheduled tasks with the at
command!