Linux 计划任务at命令

at在一个指定的时间执行一个指定任务,只能执行一次且需要开启atd进程。

命令参数:

-m 当指定的任务被完成之后,将给用户发送邮件,即使没有标准输出

-I atq的别名

-d atrm的别名

-v 显示任务将被执行的时间

-c 打印任务的内容到标准输出

-V 显示版本信息

-q< > 使用指定的列队

-f< > 从指定文件读入任务而不是从标准输入读入

-t< > 以时间参数的形式提交要运行的任务

1.查看是否按照at命令

chkconfig --list | grep atd

atd  0:off   1:off   2:off   3:on    4:on    5:on    6:off

# 3 和 5 级别是字符界面和图像界面这两个 on就表示已经安装

2.查看atd服务状态

ps -ef | grep atd   或者   service atd status

3.开启用/etc/init.d/atd start or restart

备注:配置一下启动时就启动这个服务,免得每次重新启动都得再来一次

命令:chkconfig atd on或者chkconfig --level 2345 atd on


4.执行方式和权限

at 命令产生的所要运行的计划任务,将以文字档的方式写入 /var/spool/at/ 目录内,以便等待 atd 这个服务的取用与运行。

我们可以利用 /etc/at.allow /etc/at.deny 这两个文件来进行 at 的使用限制。加上这两个文件后, at 的工作情况是这样的:

先找寻 /etc/at.allow 这个文件,写在这个文件中的使用者才能使用 at ,没有在这个文件中的使用者则不能使用 at (即使没有写在 at.deny 当中);

如果 /etc/at.allow 不存在,就寻找 /etc/at.deny 这个文件,若写在这个 at.deny 的使用者则不能使用 at ,而没有在这个 at.deny 文件中的使用者,就可以使用 at 命令了。

如果两个文件都不存在,那么只有 root 可以使用 at 这个命令。

5.at时间指定

  1. HH:MM 如: at 02:30
  2. HH:MM YYYY-MM-DD 如:at 8:00 2020-01-01
  3. HH:MM[am | pm] [month] [date] 如:at 8:00 Oct 1 # 在十月一号的八点
  4. HHlMM[am | pm] + number [minutes | hours | days | weeks] 如:at 8:00 + 1days
  5. 最常用的的一个时间:now + 时间 比如在十分钟后:at now + 10 minutes,在一天后:at now + 1 days


三个星期后的下午 5 点钟执行 /bin/ls : 
at 5pm + 3 weeks /bin/ls
1999 年的最后一天的最后一分钟印出 the end! 
at 23:59 12/31/1999 echo the end!   

使用at指定时间运行程序。

[root@bogon test]# at -f /var/tmp/test/arc.sh 1:30 12/30/18

job 6 at 2018-12-30 01:30

三天后的下午 5 点钟执行/a.sh

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

at< /a.sh

at<

job 7 at 2018-01-08 17:00

[root@localhost ~]#

明天17点钟,输出时间到指定文件内

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

at< date </root/2013.log

at<

job 8 at 2018-01-06 17:20

查看当前用户所有at任务: at -l

查看8号任务详情: at -c 8

删除8号任务:at -d 8

at -l







猜你喜欢

转载自blog.csdn.net/weixin_42296389/article/details/80571501