Low Orbit Flux Logo 2 F

Linux Command - at

The Linux at command allows you to schedule other commands to run at a specific time. It also comes together wtih the batch command ( at -b ).

at runs commands at a scheduled time
batch runs commands when the system load average is less than 0.8


sudo apt install at
sudo systemctl status atd

List all scheduled jobs:



atq     

Same:



at -l

Show command or content of a job by job ID:



at -c 56

Shows the job number, time/date, queue, and user.

Show specific queue ( ex: queue m ):



atq -q m
at -l -q m

Delete job by job number, use any of these commands:



atrm 56
at -r 56
at -d 56

Scheduling

Run a command at specified time. Input command interactively:



at 17:00

echo "test"

[enter]
[ctrl] - d

Run a shell script:



at 17:00 -f /home/user1/test1.sh

Pipe command to at:



echo "echo 'test'" | at 17:00

Using a heredoc:



at 17:00 <<END
> echo "test"
> END

Alternate ways of specifying the time:



at 5pm      -f /home/user1/test1.sh        # 12 hour clock
at midnight -f /home/user1/test1.sh        # midnight
at noon     -f /home/user1/test1.sh        # noon
at teatime  -f /home/user1/test1.sh        # 4pm
at now      -f /home/user1/test1.sh        # right now
at now +3 hours -f /home/user1/test1.sh    # 3 hours later
at today        -f /home/user1/test1.sh    # right now
at 17:15 today  -f /home/user1/test1.sh    # 17:15 same day
at tomorrow     -f /home/user1/test1.sh    # in 24 hourse
at 5:15pm tomorrow -f /home/user1/test1.sh # 5:15pm tomorrow
at Friday          -f /home/user1/test1.sh # on Friday
at 17:00 Friday    -f /home/user1/test1.sh # on Friday at 17:00
at 17:00 Friday +2 weeks -f /home/user1/test1.sh  # 2 weeks from Friday at 17:00

Using dates:



at Aug 21        -f /home/user1/test1.sh 
at Aug 21 2024   -f /home/user1/test1.sh  
at 08/21/24      -f /home/user1/test1.sh  
at 21.08.24      -f /home/user1/test1.sh  
at 24-08-21      -f /home/user1/test1.sh  
at 2024-08-21       -f /home/user1/test1.sh  
at 5pm 2024-08-21   -f /home/user1/test1.sh  
at -t 202308161708.30 -f home/user1/test1.sh        #  exact time and date YYYYMMDDhhmm.ss

Queues

a default queue for at
b default queue for batch
= currently running queue


at 4pm -f file.sh -q s

Batch Command

This command will run when the load average is below 0.8. It is similar to the at command except that it won’t accept time, command, or script parameters. You can input the command interactively. You can also use a pipe or heredoc block.



batch 17:00 <<END
> echo "test"
> END

Mail

By default at will send output as mail but only if there is output. This can be overridden.

Override:



at 4pm -f /home/user1/test1.sh -m   # ensure mail is sent
at 4pm -f /home/user1/test1.sh -M   # suppress sending mail