linux定时任务:
[ @ops_operator_01 ~]$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
创建秒级定时任务案列:
[root@localhost ~]# mkdir /server/scripts -p (递归创建一个文件目录)
[root@localhost ~]# cd /server/scripts
[root@localhost scripts]# vi miao.sh (创建一个简单的秒脚本文件)
#!/bin/sh
while true #(使用while循环)
do
echo 测试正常 #(返回值:测试正常)
sleep 1 #(中间停顿1秒)
done
~
~
~
~
"miao.sh" [New] 6L, 53C written
[root@localhost scripts]# sh miao.sh
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
[root@localhost scripts]# vi miao.sh
#!/bin/sh
while true
do
echo 测试正常 >>/tmp/a.log #(添加后台文件/tmp/a.log,可在后台运行)
sleep 1
done
~
~
"miao.sh" 6L, 72C written
[root@localhost scripts]# sh miao.sh & (使用sh+文件名+&可执行后台文件)
[1] 14069
[root@localhost scripts]# ps -ef|grep miao (查看秒级任务运行状态)
root 14069 13730 0 00:33 pts/0 00:00:00 sh miao.sh
root 14146 13730 0 00:35 pts/0 00:00:00 grep --color=auto miao
[root@localhost scripts]# tail -f /tmp/a.log (监控后台任务运行状态)
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
测试正常
[root@localhost scripts]# ps -ef|grep miao (查看秒级任务运行状态)
root 14069 13730 0 00:33 pts/0 00:00:00 sh miao.sh
root 14189 13730 0 00:35 pts/0 00:00:00 grep --color=auto miao
[root@localhost scripts]# kill 14069 (kill+PID终结任务)
[root@localhost scripts]# ps -ef|grep miao
root 14200 13730 0 00:36 pts/0 00:00:00 grep --color=auto miao
[1]+ 已终止 sh miao.sh