|
在一些系统里,要启动 at 就要启动 atd 服务,启动 atd 服务执行以下命令:
service atd start
提交一个定时作业(定时在07:08分时从 / 目录查找所有包含 passwd 字符串的文件):# at 07:08
warning: commands will be executed using /bin/sh
at> find / -name "passwd" -print
at> <EOT>
job 6 at 2010-02-05 07:08 上面的 <EOT> 是按了 ctrl + d 组合键后的结果,表示结束提交任务。
当这个任务完成后,系统会发送一个 mail 到你的邮箱:From [email=root@222225-slot5]root@222225-slot5[/email] Fri Feb 5 15:08:02 2010
X-Original-To: root
Delivered-To: [email=root@222225-slot5]root@222225-slot5[/email]
Subject: Output from your job 6
To: [email=root@222225-slot5]root@222225-slot5[/email]
Date: Fri, 5 Feb 2010 15:08:01 +0800 (CST)
From: [email=root@222225-slot5]root@222225-slot5[/email] (root)
/etc/default/passwd
/etc/pam.d/passwd
/etc/passwd
/opt/software/etc/default/passwd
/opt/software/etc/pam.d/passwd
/opt/software/etc/passwd
/opt/software/var/run/nscd/passwd
/opt/software/usr/bin/passwd
/var/run/nscd/passwd
/usr/bin/passwd
/usr/lib/news/bin/auth/passwd
/usr/share/doc/packages/pam_ldap/pam.d/passwd at 命令可以接受多种时间格式,详情查看 man 文档。
当然,可以提交多个计划任务,如果想查看所有的计划任务,可以用 -l 参数,如:222225-slot5:~ # at 07:28
warning: commands will be executed using /bin/sh
at> echo "hello world" > test.txt
at> <EOT>
job 9 at 2010-02-05 07:28
222225-slot5:~ # at 07:29
warning: commands will be executed using /bin/sh
at> echo "how are you" >> test.txt
at> <EOT>
job 10 at 2010-02-05 07:29
222225-slot5:~ # at -l
9 2010-02-05 07:28 a root
10 2010-02-05 07:29 a root 当两个任务顺利完成后,会在家目录下生成相应的文件:222225-slot5:~ # cat test.txt
hello world
how are you 提交一个明天的计划任务,这个任务是让系统自动去执行一个脚本:222225-slot5:~ # at 3:00pm tomorrow -f /root/hello.sh
warning: commands will be executed using /bin/sh
job 12 at 2010-02-06 15:00
可以不用像上面那在命令行中逐行输入命令,而是先将命令写入到一个文件里,然后以 -f 参数指定这个文件来运行:
[Plain Text] 纯文本查看 复制代码 at [-f filename] time
对于上面的 time ,可以指定如下格式:
具体指定的时间,如 now, noon, midnight, teatime(4PM) 标准的日期格式,比如 MMDDYY, MM/DD/YY, DD.MM.YY 文本日期格式,如 Jul 4 或 Dec 25,有没有年份都不要紧 指定时间增量,如 Now + 25 minutes , 10:16PM tomorrow 10:16 + 7 days 如果指定一个已经过去的时间,那么 at 命令将在第 2 天的那个时候执行作业。
使用 at 命令时,作业将提交到作业队列(job queue)中。作业队列保存 at 命令提交的作业。有 26 种作业队列可用于不同的优先级水平,使用小写字母 a 到 z 引用作业队列。默认情况下,所有的 at 作业都提交到作业队列 a,即最高的优先级队列。如果希望以较低的优先级运行作业,那么可以用 -q 参数指定字母。
清除一个计划任务使用 atrm 命令,其格式是:
atrm [job no] 或者 at -r [job no]
要清除一个计划任务,首先要执行 at -l 命令,以获取相应的计划任务标识,然后对计划任务使用 at -r 命令,清除该任务:222225-slot5:~ # at -l
9 2010-02-05 07:28 a root
10 2010-02-05 07:29 a root
222225-slot5:~ # atrm job 9
10 2010-02-05 07:29 a root |
|