您的位置:首页 > 运维架构 > Linux

一天一条Linux指令-at

2016-11-03 12:56 211 查看


用途说明

at命令用于在指定时间执行一次任务。如果任务需要重复执行,需用crontab。

atq用于打印队列中的任务,atrm用于删除任务。


常用参数

at TIME 用于设定指定时间的任务,其中TIME有很多表达方式。

at -f job.sh TIME 在指定时间执行job.sh。


使用示例


示例一

[root@jfht ~]# date 

2010年 09月 30日 星期四 21:11:07 CST

[root@jfht ~]# at now + 5 minutes 

at> date

at> <EOT>

job 1 at 2010-09-30 21:16

过了六七分钟之后 

[root@jfht ~]# date 

2010年 09月 30日 星期四 21:19:58 CST

[root@jfht ~]#

奇怪,在21点16分时没有打印出当前的时间。

可能发送到邮箱了,使用mail命令检查一下。

[root@jfht ~]# mail 

Mail version 8.1 6/6/93.  Type ? for help.

"/var/spool/mail/root": 20882 messages 1 new 20882 unread



Message 20883:

From root@localhost.localdomain  Thu Sep 30 21:16:00 2010

Date: Thu, 30 Sep 2010 21:16:00 +0800

From: root <root@localhost.localdomain>

Subject: Output from your job        1

To: root@localhost.localdomain

2010年 09月 30日 星期四 21:16:00 CST


示例二

[root@jfht ~]# at -f ./job.sh now + 5 minutes 

job 2 at 2010-09-30 21:42

[root@jfht ~]# atq 

2       2010-09-30 21:42 a root

[root@jfht ~]#

过了五分钟之后。

[root@jfht ~]# cat job.txt 

2010年 09月 30日 星期四 21:42:00 CST

 


示例三

[root@jfht ~]# date 

2010年 09月 30日 星期四 21:44:58 CST

[root@jfht ~]# at 5pm + 3 days /bin/ls 

syntax error. Last token seen: /

Garbled time
在Linux宝库上的例子有错,命令行上不能直接跟任务命令行。 

[root@jfht ~]# at 5pm + 3 days 

at> <EOT>

job 3 at 2010-10-03 17:00

[root@jfht ~]# atq 

3       2010-10-03 17:00 a root

[root@jfht ~]# at 5pm + 2 weeks 

at> <EOT>

job 5 at 2010-10-14 17:00

[root@jfht ~]# at 17:20 tomorrow 

at> <EOT>

job 6 at 2010-10-01 17:20

[root@jfht ~]# at 23:59 12/31/1999 

at> <EOT>

job 7 at 1999-12-31 23:59

此处时间在过去!!! 

[root@jfht ~]# atq 

6       2010-10-01 17:20 a root

3       2010-10-03 17:00 a root

5       2010-10-14 17:00 a root

注意没有任务7。 

[root@jfht ~]# at 10:40 10/1/2010 

at> <EOT>

job 8 at 2010-10-01 10:40

[root@jfht ~]# atq 

6       2010-10-01 17:20 a root

8       2010-10-01 10:40 a root

3       2010-10-03 17:00 a root

5       2010-10-14 17:00 a root

[root@jfht ~]#

[root@jfht ~]# atrm 3 

[root@jfht ~]# atq 

6       2010-10-01 17:20 a root

8       2010-10-01 10:40 a root

5       2010-10-14 17:00 a root
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: