crontab秒级执行脚本
crontab任务配置基本格式:
* * * * * command
例子:
# 每月的最后1天
0 0 L * * *
说明:
Linux
* * * * *
- - - - -
| | | | |
| | | | +----- day of week (0 - 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | +---------- month (1 - 12) OR jan,feb,mar,apr ...
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- minute (0 - 59)
第一:
秒级执行脚本
写个小脚本,配置上你要执行的脚本run.sh
vim shell.sh
#!/bin/bash
while :
do
/root/run.sh
sleep 10 # 延迟10秒执行
done
然后
nohup sh shell.sh &
方法二: crontab中增加延迟30秒来实现
[root@host ~]# cat log.txt
2018-11-21 09:00:00
2018-11-21 09:00:30
2018-11-21 09:01:00
2018-11-21 09:01:30
2018-11-21 09:02:00
2018-11-21 09:02:30
......
[root@host ~]# crontab -l
* * * * * /var/script/run.sh >> log.txt
* * * * * sleep 30; /var/script/run.sh >> log.txt
[root@host ~]# cat run.sh
#!/bin/bash
date +'%Y-%m-%d %H:%M:%S'