码迷,mamicode.com
首页 > 其他好文 > 详细

[RH134] 3-计划任务

时间:2020-03-24 09:21:51      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:内容   事件   提交   一周   shel   deny   centos7   ctr   ==   

1.at计划任务

at计划任务,只在某个指定的事件执行一次的任务。

1)在某一天执行一个脚本

[root@centos7 xx]# at 2020-3-25
at> /bin/aa.sh
at> <EOT>
job 2 at Wed Mar 25 15:31:00 2020

我们这里的时间只精确到了天,则任务执行的具体时间是提交任务的时间点(指定的那天)。例如这个例子,任务执行的时间点在2020-3-25的15:31:00。

注意,提交计划任务,使用 Ctrl+D 。

2)指定具体执行时间

[root@centos7 xx]# at 10:00 2020-3-25   
at> /bin/aa.sh
at> <EOT>
job 3 at Wed Mar 25 10:00:00 2020

注意,具体时间只能精确到分(不能精确到秒),时间是采用的24小时制。

3)一段时间之后执行

[root@centos7 xx]# at 4:00 + 1weeks
at> /bin/aa.sh
at> <EOT>
job 4 at Mon Mar 30 04:00:00 2020

一周后的那天的早上4点执行。时间单位有:minutes, hours, days, weeks。如果在某段时间后的此时执行,可以使用 at now + 3days 。

4)查看已存在的计划任务

[root@centos7 xx]# atq
2       Wed Mar 25 15:31:00 2020 a root
3       Wed Mar 25 10:00:00 2020 a root
4       Mon Mar 30 04:00:00 2020 a root
6       Thu Mar 26 15:38:00 2020 a root
[root@centos7 xx]# at -l
2       Wed Mar 25 15:31:00 2020 a root
3       Wed Mar 25 10:00:00 2020 a root
4       Mon Mar 30 04:00:00 2020 a root
6       Thu Mar 26 15:38:00 2020 a root

5)如何查看at计划任务具体执行的内容

cd /var/spool/at
[root@centos7 at]# ls
a0000201931e03  a0000301931cb8  a0000401933770  a00006019323aa  spool

可以看到,所有计划任务对应的文件,第5位的数字对应计划任务的编号。我们可以打开文件:

[root@centos7 at]# cat a0000201931e03 
#!/bin/sh
# atrun uid=0 gid=0
...
...
${SHELL:-/bin/sh} << marcinDELIMITER59a4f86f
/bin/aa.sh

在最后,我们可以看到我们执行的脚本是 /bin/aa.sh 。

6)删除at计划任务

[root@centos7 at]# atrm 2
[root@centos7 at]# at -d 3

使用atrm或at -d加上任务编号就可以删除。

删除1-6号任务:

atrm {1..6}

7)计划任务的权限

如果我们不想让某个用户拥有做计划任务的权限,可以编辑 /etc/at.deny :

leo
kale

将需要拒绝的用户名写到文件中,一行一个用户名。

 

 

 

 

===

[RH134] 3-计划任务

标签:内容   事件   提交   一周   shel   deny   centos7   ctr   ==   

原文地址:https://www.cnblogs.com/leokale-zz/p/12543681.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!