Thursday, 24 December 2009

Scheduling commands with "at" command

To schedule job to run at 20:00 the same day enter following command

at -m 2000

Running at with valid time takes you to at> prompt where you can enter the script or command you want to run then hit to exit "at" and save the scheduled job.

You can check your job has been scheduled to run at 8pm by using the atq command.

Other valid time formats to use with “at” command.
The above is practical is you want to schedule a command for same day, if you want to schedule the command for a specific date you have following options.

“at” allows a date parameter after the time, it allows shorthand notations like tomorrow and increments on the set time like next week.

at -m 2230 tomorrow (easy notation for scheduling cmd at 10:30pm tomorrow)

at -m 2pm next week (schedule for 2pm next week)

at -m 2pm + 1 week (schedule for 1 week increment from 2pm current day, equivalent of previous example)

Specifying an exact date & time.
Generally you’ll be using “at” to schedule short-term commands which don’t require a full crontab entry so current day or tomorrow tends to be the most used options. If you wanted to run the command on a specific date you can specify date with month, date, year format.

at -m 1030 Dec 25 (schedule cmd for 10:30am on Christmas day)

btw the –m flag is optional, it sends an email to user once the scheduled command has completed.

No comments: