Skip to content
Fragmented Development

Using The 'at' Command

If you've never used the at command, you're in for a treat. The at command is a utility used to schedule jobs for execution at specific times. The syntax is very simple, and should be easy to pick up for anyone with command-line experience.

You tell at what to do by specifying a script file, or piping output directly to at, which is my preference. For example, I run mashpodder at night to use the "bonus bytes" portion of my bandwidth cap, with the following command:

echo 'mashpodder' | at 2:30 AM

How awesome is that? at waits until 2:30 AM, executes the mashpodder command, and emails the output to my system account. Perfect!

I generally use at for bandwidth-heavy applications, so I also run system updates the same way. The following command fetches any updates for my Debian-based system:

echo 'aptitude update; aptitude -y safe-upgrade' | sudo at 3:00 AM

Notice, the sudo has to be used on the at command, not the aptitude commands. It's not going to be much good if my computer tries to prompt me for my password at 3AM!

One final use for at involves setting reminders. This is a little risky if the reminder is set too far in the future, because at jobs are not persistant and are lost when the system restarts. My method involves the spd-say command, which reads text in and outputs it through your speakers:

echo 'spd-say "Go to bed"' | at midnight

Everyone can use a little reminder now and again. One last command; to see any of the jobs you have added, you can use the atq command. It lists all of the jobs that are stored, which user it will be run as, and when it will be executed. It does not, by default, have the command itself.

Tags: linux

Add Your Comment