Affordable Web Hosting with Excellent Customer Support internet connection free month hosting

Using At to Schedule One Time Jobs

Like Cron (discussed in the IC Tech. Ref. Document: Scheduling Tasks Using Cron), the other tool used for scheduling tasks on Unix systems, At is very useful for scheduling command and script execution.

On most Unix systems, At and Cron work independently but can be used to perform similar tasks. Where Cron is used to perform tasks repeatedly, At is used to run commands or programs just once.

Scheduling Tasks With At

To add a task using At you must type at (when to execute) and hit the enter key. At will then prompt you for the command you wish to have performed. Here is an example dialog:

user@server:~/webshare$ at now + 12 hours [Hit Enter Key]
at> cat > important.backup [Hit Cntrl-D]
job 1 at Sat Jun 18 09:03:40 2002
  • The first line contains the command prompt, then the At command and lastly, the time the job is scheduled for, now + 12 or 12 hours from "now".
  • After you hit the "enter" key, At then prompts you for the command or the path to the script you want executed.
  • In this case, we're using the command cat to copy the contents of to important.backup.
  • After providing the command, or path to the script you want executed, hit Cntrl-D to let At know you're done.

In addition to the At command, there are a few other tools you can use to manipulate your tasks. For example, to view any pending tasks, type atq at the command prompt and hit enter. Another usefult tool is atrm which you can use to delete tasks. Usage of atrm requires you to call the specific task by number however, so unless you already know the number, you must discover it with atq like so:

user@server:~/webshare$ atq
18      2002-02-13 16:00 a user

And then delete: user@server:~/webshare$ atrm 18

Time Formats with At

As you saw in our example, the relatively simple syntax supported by At lends itself to quickly setting up tasks. However, this simple syntax belies the ability of At to understand complex time formats. Here's a run-down of the time formats understood by At:/p>

  • now - As you would guess, "now" mean the exact time you begin using At. However, "now" isn't really used to schedule tasks by itself. Because the time you've specified will have already passed, using "now" alone will cause the task to be run at that time on the next day. Look at the time/date modifiers, below, to fully grasp how to use "now".
  • midnight - Predictably, using "midnight" allows you to schedule tasks for that most late of hours.
  • noon - Another common sense time option for At.
  • teatime - Now you can take time out to enjoy some Earl Grey and still execute tasks on your server! "teatime" schedules jobs for 4pm.
  • 4AM(am)/4PM(pm) - You can also use HH:MM specify time.
  • MMDDYY - This as well as MM/DD/YY and MM.DD.YY will work as you'd expect.
  • Time/date Modification - All of the formats above support time/date modification using +/- Number Time-Unit. For example, at now + 12 hours would enable your job to be scheduled 12 hours from the current time.

Related Items