一天一条Linux指令-at

用途说明

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值