Scheduling ad hoc commands
The most common scheduler on Linux is, by far, Cron.
That said, it is not the only scheduler available on Linux.
While Cron has many advantages, it is relatively weak for one-off, ad-hoc commands that need to be run at a specific time in the future.
I love Cron, but it doesn't address the full use case that I need.
Enter the at command.
You can easily schedule a command to run at a specific time.
- Need to send code out for review first thing in the morning for that coworker who only skims their inbox? The at command can do that for you.
- Your company requires you to restart your machine, but the suggested time is inconvenient? The at command lets you restart on your terms.
- Want to check the status of a website in another time zone, like the European version of Reddit or Hacker News? The at command can handle that too.
However, one thing the at command doesn't do—and isn't designed to do—is run in full interactive mode.
The problem arises if you've built up a large collection of aliases that are crucial for your development work. Most of these aliases are likely stored in your interactive shell's rc files.
While the at command isn’t meant to run in interactive mode, I’ve chosen to bend the rules. I run it in full interactive mode so that I have access to all my aliases without any extra setup.
To ensure full interactive mode works seamlessly, I’ve created a system that generates scripts for each new invocation of the at command.
This setup allows me to version control every script I’ve ever run with at and provides a simple, organized script management system.
One-time setup:
alias atcommandonetimesetup='mkdir -p ~/at_scripts && touch ~/at_scripts/golden && echo "#!/bin/zsh -i" >> ~/at_scripts/golden'
Script creation:
alias atsetup='CURRENT_TIME=`date +%s`; cp ~/at_scripts/golden ~/at_scripts/$CURRENT_TIME && chmod +x ~/at_scripts/$CURRENT_TIME && vim ~/at_scripts/$CURRENT_TIME && echo ~/at_scripts/$CURRENT_TIME'
Sample workflow:
➜ / atsetup
#!/bin/zsh -i
#sudo touch /yolo
/home/$USER/at_scripts/1741579525
➜ / at now + 2 minutes
warning: commands will be executed using /bin/sh
at Mon Mar 10 04:48:00 2025
at> /home/$USER/at_scripts/1741579525
at> <EOT>
job 3 at Mon Mar 10 04:48:00 2025
➜ / atq
3 Mon Mar 10 04:48:00 2025 a $USER
➜ / atq
➜ / ls yolo
yolo