“at” utility in unix is similar to the “cron” daemon except for that “at” jobs are run only once while cron jobs are recurring. “at” is primarily used to schedule a job which can be command or a script to run once at a particular time although it can be made to reschedule the job. This could be immediatly or at a later time.
The at utility reads commands from standard input and groups them together as an at job, to be executed at a later time.
How to Create an at Job:
Start the at utility, specifying the time you want your job executed.
$ at [-m] time [date]
"-m"
Sends you email after the job is completed.
time
Specifies the hour that you want to schedule the job. Add am or pm if you do not specify the hours according to the 24-hour clock. Acceptable keywords are midnight, noon, and now. Minutes are optional.
date
Specifies the first three or more letters of a month, a day of the week, or the keywords today or tomorrow.
At the at prompt, type the commands or scripts that you want to execute, one per line.
You may type more than one command by pressing Return at the end of each line.
Exit the at utility and save the at job by pressing Control-D.
Your at job is assigned a queue number, which is also the job's file name. This number is displayed when you exit the at utility.
Example 14-7 Creating an at Job
The following example shows the at job that created to remove backup files at 7:30 p.m.
$ at -m 1930
at> rm /home/jones/*.backup
at> Press Control-D
job 897355800.a at Thu Jul 12 19:30:00 2011
Your “at” job “rm /home/jones/*.backup”
completed.
scheduling a large "at" job for 4:00 a.m. Saturday morning. The job output was directed to a file named big.file.
$ at 4 am Saturday
at> sort -r /usr/dict/words > /export/home/jones/big.file
AT jobs:
To get a list of all JOBS on the Sun Server:
sunsolaris# at -l
user = root 1210161000.a Wed May 7 12:50:00 2011
user = root 1210161001.a Wed May 7 12:50:01 2011
user = root 1210198500.a Wed May 7 23:15:00 2011
user = root 1210331460.a Fri May 9 12:11:00 2011
user = root 1210198320.a Wed May 7 23:12:00 2011
To run a command at a particular time
sunsolaris# at -t 201105072312
at> reboot
at> <EOT>
commands will be executed using /sbin/sh
job 1210198320.a at Wed May 7 23:12:00 2011
In the above -t switch defines the time that follows it as the time at which the one or more command that follows at the “at>” prompt to be run. Once, all the commands are entered press “CTRL+D” to make “at” aware of the end of commands.
Run a job now
sunsolaris# at now
at>reboot
at> <EOT>
commands will be executed using /sbin/sh
job 1210100190.a at Tue May 6 19:56:30 2011
Run at noon (12pm)
sunsolaris# at noon
at> uname -a
at> <EOT>
commands will be executed using /sbin/sh
job 1210158000.a at Wed May 7 12:00:00 2011
Run at midnight
sunsolaris# at midnight
at> uname -a
at> <EOT>
commands will be executed using /sbin/sh
job 1210114800.a at Wed May 7 00:00:00 2011
To run a job “n” mins from now
Say you want to run the command in 5 minutes from now
sunsolaris# at now + 5minutes
at> uname -a
at> <EOT>
commands will be executed using /sbin/sh
job 1210100631.a at Tue May 6 20:03:51 2011
To run a script or a file
sunsolaris# at -f /root/myscript now
The above runs the script /root/myscript immediatly. The switch “-f” defines the file to be run instead of commands.
To remove/cancel an at job
sunsolaris# at -r <jobname>
For instance, to cancel the last job “1210100631.a” job.
sunsolaris# at -l
user = root 1210161000.a Wed May 7 12:50:00 2011
user = root 1210161001.a Wed May 7 12:50:01 2011
user = root 1210198500.a Wed May 7 23:15:00 2011
user = root 1210331460.a Fri May 9 12:11:00 2011
user = root 1210198320.a Wed May 7 23:12:00 2011
user = root 1210158000.a Wed May 7 12:00:00 2011
user = root 1210114800.a Wed May 7 00:00:00 2011
user = root 1210100631.a Tue May 6 20:03:51 2011
sunsolaris# at -r 1210100631.a
sunsolaris# at -l
user = root 1210161000.a Wed May 7 12:50:00 2011
user = root 1210161001.a Wed May 7 12:50:01 2011
user = root 1210198500.a Wed May 7 23:15:00 2011
user = root 1210331460.a Fri May 9 12:11:00 2011
user = root 1210198320.a Wed May 7 23:12:00 2011
user = root 1210158000.a Wed May 7 12:00:00 2011
user = root 1210114800.a Wed May 7 00:00:00 2011
Now, you can see the last job removed from the scheduled list.
The at jobs are saved as files under
/var/spool/cron/atjobs
To see whats in a job, do a “cat”
sunsolaris# cat 1210114800.a
To Check the Background Running JOBS:
bash-3.00$ ps -ef | grep scp
To see the background SCP processes.
< NOTE: You have to generate auto authentication keys to login to remote server in case of SCP using "at". Please follow the link:
http://www.blogger.com/blogger.g?blogID=7924871323222705884#editor/target=post;postID=4882376238911253462
>
------------------------------------------------------------------------------------------
Thanks for reading this article.
Comments
Post a Comment