One-off scheduled jobs locally

· 190 words · 1 minute read

I had an idea to build a tool that was similar to cron, but for one off jobs. Imagine deploying some test infrastructure with terraform, and I want to schedule destroying it tomorrow, in case I forget to come back and destroy it.

For once in my life, I looked to see if such a tool existed before diving in and building it, and lo and behold, at exists!

$ terraform apply
<output of the apply>
...
$ at + 24 hours
terraform destroy
job 8 at Tue Jul  8 8:00:00 2025

(pressing ctrl + d to close the prompt).

I can check the existing jobs:

$ atq
8   Tue Jul  8 8:00:00 2025

See what the job is

$ at -c 8
<exporting environment variables>
cd /path/where/i/ran/at/from || {
    echo 'Execution directory inaccessible' >&2
    exit 1
}
terraform destroy

Delete the job

atrm 8

And there’s a few other features I’m not currently interested in yet. Pretty neat! And it’s builtin to MacOS! It only needed to be enabled (man atrun).

Time will tell if this is useful enough to keep using, but I’m satisfied with what I’ve discovered.