2022-01-16 18:20:39 +00:00
|
|
|
---
|
|
|
|
title: "at"
|
2022-01-26 21:29:48 +00:00
|
|
|
tags: [ "Documentation", "Basics" ]
|
2022-01-16 18:20:39 +00:00
|
|
|
---
|
2021-05-15 14:41:45 +00:00
|
|
|
Install with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo apt install at
|
|
|
|
```
|
2021-05-15 14:41:45 +00:00
|
|
|
|
|
|
|
Enable the daemon service with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo systemctl enable --now atd
|
|
|
|
```
|
2021-05-15 14:41:45 +00:00
|
|
|
|
2020-01-02 00:04:35 +00:00
|
|
|
Then jobs can be specified with absolute time, such as:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
at 16:20
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
at noon
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
at midnight
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
at teatime
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2021-05-15 14:41:45 +00:00
|
|
|
Type in your command, e.g.:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
touch /tmp/$FILE.txt
|
|
|
|
```
|
2021-05-15 14:41:45 +00:00
|
|
|
|
2020-01-02 00:04:35 +00:00
|
|
|
The jobs can also be specified relative to the current time:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
at now +15 minutes
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Finally, accept the jobs with ^D.
|
|
|
|
|
|
|
|
# Managing `at` Jobs
|
|
|
|
|
|
|
|
Display a list of commands to run with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
atq
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
> 2 Sat Oct 20 16:00:00 2018 a roach-1
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
This will print all pending IDs. Remove a job by the ID with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
atrm 2
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
Check `/var/spool/atd/` to see the jobs.
|
2023-04-13 04:06:54 +00:00
|
|
|
|
2023-04-13 20:23:05 +00:00
|
|
|
![At it again](/tapes/at.gif)
|
2023-04-13 04:18:57 +00:00
|
|
|
|
2023-04-13 04:06:54 +00:00
|
|
|
## Automation
|
|
|
|
|
|
|
|
Automatically add a job for later, by setting the date, then using echo for the command.
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
t="$(date -d "2 minutes" +%R)"
|
|
|
|
echo "fortune > ~/$FILE" | at "$t"
|
|
|
|
watch cat $FILE
|
|
|
|
```
|
2023-04-13 04:06:54 +00:00
|
|
|
|
|
|
|
The `$t` here outputs the day in minutes, but you could also do `t="$(date -d "2 days" +%m/%d/%Y)"`.
|