Post Viewer - 20140404.HTM

Dead Simple Command Scheduling with “at”

It’s way past when you should have gone to sleep, but you’d just like to update one more time, download this file, build and install it, and restart a couple of services.  The bed is calling, though.  Luckily, the notion that Linux users can work computers in their sleep is actually quite accurate.  Let’s take a look at “at,” a dead simple, human-readable tool you can use to schedule commands in advance.

  1. Open a terminal and type at followed by a time, like 10:00 today, 16:43 tomorrow, 02:30 June 10, or even now + 20 minutes
  2. Type each of your commands in the order you’d like them to run
  3. Press Ctrl-D to save and schedule

If at any time you’d like to see what you have scheduled, use the command atq.  To remove a job from the queue, use atrm plus the job number shown by atq.

Hard to mess that up, even if you’re half-conscious!

Examples:

demo of at command

demo of at command

demo of at command

Update:  Guido Stepken shared some great advice with the OMG! Ubuntu! G+ on when you should combine cron and at.

Just a small suggestion for Linux users, who don’t have their notebook/desktop/… running every day.

There is a fundamental difference between cron and at: Cron typically is used for repeated jobs, at typically used for one-time jobs. Both can schedule jobs at a certain time. So far they seem to do the same thing.

But what happens, if you have scheduled daily backups and after 3 weeks you return home and start your Linux? It executes 21 times the same backup! All passed jobs during that time being powered off, then are being executed, totally blocking yor machine! CRON: No job is forgotten. On contrary, at forgets about all jobs, he couldn’t execute, because of having been switched off!

Another situation: One admin has the machine doing backups at 16.00 every workday. Another admin does a kernel update between 15.59 and 16.05. Then you have no backup!??

So, correct use always is letting cron schedule an at job which schedules then the backup. So, after 21 days – being back again, switching on your Linux, no 21 backups are executed, before you can really use it!

Last Updated: 2015-04-16 - Questions? Feedback? Send me a note!