Linux 'at' Command
The at command in Linux is used to schedule a command or script to run at a specific time in the future. It is a powerful tool for task scheduling.
Options
-f: Specifies a file containing the commands to be executed.-m: Sends an email to the user after the job is completed, even if there is no output.-v: Displays the time the job is scheduled to run.-l: Lists the user's pending jobs (same asatq).-d: Deletes a job by its job number (same asatrm).-q: Specifies the queue to use (default isa).-t: Specifies the time in the format[[CC]YY]MMDDhhmm[.ss]to run the job.-c: Displays the contents of a job.--help: Displays help information for theatcommand.--version: Displays the version of theatcommand.
Examples
1. Schedule a Command to Run at a Specific Time
To schedule a command to run at 3:00 PM:
echo "ls -l" | at 3:00 PM
2. Schedule a Script Using a File
To schedule a script stored in a file:
at -f myscript.sh 5:00 PM
3. List Pending Jobs
To view all scheduled jobs:
at -l
4. Remove a Scheduled Job
To remove a job with job number 2:
at -d 2
5. Remove a Scheduled Job
To remove a job with job number 2:
atrm 2
6. Schedule a Command with Email Notification
To schedule a command and receive an email notification:
echo "df -h" | at -m 6:00 PM
7. Schedule a Command with now to
To schedule a command to run 10 minutes from now:
echo "echo 'Hello, World!'" | at now + 10 minutes
8. Schedule a Command for next month
To schedule a command to run on the first day of next month at 8:00 AM:
echo "echo 'New month started!'" | at 8:00 AM next month
9. Schedule a Command with tomorrow
To schedule a command to run tomorrow at 9:00 AM:
echo "echo 'Good morning!'" | at 9:00 AM tomorrow
10. Schedule a Command for 1week
To schedule a command to run in one week at 10:00 AM:
echo "echo 'One week later!'" | at 10:00 AM + 1 week
echo "echo 'One week later!'" | at 10:00 AM + 2 week
11. Schedule a Command for 1 year
To schedule a command to run in one year at 11:00 AM:
echo "echo 'One year later!'" | at 11:00 AM + 1 year
Notes
The at command requires the atd daemon to be running on your system. Ensure it is enabled and started before using the at command.