定时任务调度
定时任务调度
crond 任务调度
为什么要定时调度
注意星号之间要有间隔
*/1 * * * * ls -l /etc/ > /tmp/to.txt
1
crontab使用脚本应用实例
第一步:添加mywork.sh 脚本
第二步:添加sh脚本的执行权限
第三步:添加定时任务
[root@Tyc home]# vim mywork.sh [root@Tyc home]# chmod u+x mywork.sh [root@Tyc home]# ll total 12 -rw-r--r-- 1 tom root 0 Feb 22 18:46 apple.txt -rw-r--r-- 1 root root 0 Feb 21 12:28 cat.txt -rwxr--r-- 1 root root 39 Feb 22 20:42 mywork.sh -rw-r--r-- 1 root root 0 Feb 21 19:59 pig.txt -rw-r--r-- 1 root root 48 Feb 21 19:11 test.txt -rw-r--r-- 1 root root 0 Feb 21 19:59 tiger.txt drwx------ 2 tom wudang 4096 Feb 22 19:00 tom [root@Tyc home]# crontab -e no crontab for root - using an empty one crontab: installing new crontab [root@Tyc home]# crontab -l */1 * * * * /home/mywork.sh [root@Tyc home]# ll total 16 -rw-r--r-- 1 tom root 0 Feb 22 18:46 apple.txt -rw-r--r-- 1 root root 0 Feb 21 12:28 cat.txt -rw-r--r-- 1 root root 162 Feb 22 20:45 mycal -rwxr--r-- 1 root root 39 Feb 22 20:42 mywork.sh -rw-r--r-- 1 root root 0 Feb 21 19:59 pig.txt -rw-r--r-- 1 root root 48 Feb 21 19:11 test.txt -rw-r--r-- 1 root root 0 Feb 21 19:59 tiger.txt drwx------ 2 tom wudang 4096 Feb 22 19:00 tom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
at 定时任务
crond是定时、反复执行的。
at命令是一次性定时计划任务。
启动的前提是看at的守护进程atd是否在运行
查看指令是
ps -ef | grep atd
。[root@Tyc home]# ps -ef | grep atd root 1089 1 0 Feb21 ? 00:00:00 /usr/sbin/atd -f
1
2
[root@Tyc home]# atq [root@Tyc home]# at 5pm tomorrow at> date > /home/test.log<EOT> job 1 at Wed Feb 23 17:00:00 2022 [root@Tyc home]# atq 1 Wed Feb 23 17:00:00 2022 a root [root@Tyc home]#
1
2
3
4
5
6
7at+选项+时间
之后输入回车
,然后输入指令,最后按两次ctrl+D
结束输入。可以采用
atq
查看设置的定时任务。atrm +编号
:删除该编号的定时任务。at [选项] [时间]
。
上次更新: 2025/06/25, 11:25:50