580
◾
Linux with Operating System Concepts
is scheduled to take place at 2:30 PM of the next day. You can also use the words
today
or
tomorrow
for the date, as in
2:30
PM tomorrow
or
23:59 today
.
The alternative for the time/date is to specify a time/date relative to the time that the at
command is submitted. This is specified using the notation:
now
+
count unit
, where
count
is an integer and
unit
is a temporal unit such as minutes, hours, or days. Here are
some examples:
• now
+
5 minutes
• now
+
2 hours
• now
+
7 days
• now
+
4 weeks
You can combine relative and absolute methods but it may not make much sense. For
instance,
now
+
12:00 PM
makes
no sense at all but
now
+
3 days
would schedule the
event at the current time in 3 days. Errors in the time/date specification will yield the mes-
sage
Garbled time
. Note that at schedules events to the minute, not to the second. You
would never specify the seconds unit for either an absolute or a relative time specification.
The event to be scheduled can be either specified in a separate file or through the com-
mand line. As an example, you have written the activities to be scheduled
in the shell script
my_event.sh
. You would then schedule this using
at
time/date specifier
–f ./my_event.sh
where
time/date specifier
is as explained above. The –f option indicates that the event(s) to
take place is(are) stored in the accompanying file. The file does not have to be a script. It
could comprise Linux commands or invoke a script.
The alternate approach to specifying the event(s) in a file is to omit the –f option. In this
case, upon hitting
<
enter
>
,
you are dropped into an
at
>
prompt. You now enter your
commands one line at a time, pressing the
<
enter
>
key to end each line. To exit the
at
>
prompt, press
control
+
d
.
For instance, you might specify
at now
+
1 minute
Since you did not include –f filename, you now see
at
>
You might then enter
at
>
mount 10.11.12.13:/home/backup/mnt/backup
at
>
tar –xzf /home/* /mnt/backup/home-backup.tar
at
>
umount /mnt/backup
at
>
control
+
d
Maintaining and Troubleshooting Linux
◾
581
Thus, in 1 minute time, you will use tar to create a backup on
a mounted file server and
then unmount the file server when done.
Once events are scheduled, you can examine them using
atq
. This lists each waiting
event scheduled through at or batch. You can remove any scheduled item using
atrm
. If
there is only
one item in the event queue,
atrm
will delete it. Otherwise, when you use
atq
, each event is numbered and you will have to specify the number of the event with
atrm as in
atrm 2
to remove the second item in the scheduled list.
The batch command is identical to the at command except that you do not specify a
time. If you specify batch by itself, you are dropped into the at
>
prompt; otherwise, you
would specify
batch –f
Do'stlaringiz bilan baham: