crontab

作者: Marksirl | 来源:发表于2020-07-12 17:15 被阅读0次

crontab常规使用

minute hour day of mouth month of year day of week Command
0~59 0~23 1~31 1~12 0~6 Shell
5   * * * * Command    每小时的第5分钟执行一次命令
30 18 * * * Command    指定每天下午的 6:30 执行一次命令
30  7 8 * * Command    指定每月8号的7:30分执行一次命令
30  5 8 6 * Command    指定每年的6月8日5:30执行一次命令
30  6 * * 0 Command    指定每星期日的6:30执行一次命令

每天的下午4点、5点、6点的5 min、15 min、25 min、35 min、45 min、55 min时执行命令。
5,15,25,35,45,55 16,17,18 * * * Command

crontab秒级任务使用

硬方法如下

* * * * * /usr/bin/curl http://www.test.com
* * * * * sleep 5; /usr/bin/curl http://www.test.com
* * * * * sleep 10; /usr/bin/curl http://www.test.com
* * * * * sleep 15; /usr/bin/curl http://www.test.com
* * * * * sleep 20; /usr/bin/curl http://www.test.com
* * * * * sleep 25; /usr/bin/curl http://www.test.com
* * * * * sleep 30; /usr/bin/curl http://www.test.com
* * * * * sleep 35; /usr/bin/curl http://www.test.com
* * * * * sleep 40; /usr/bin/curl http://www.test.com
* * * * * sleep 45; /usr/bin/curl http://www.test.com
* * * * * sleep 50; /usr/bin/curl http://www.test.com
* * * * * sleep 55; /usr/bin/curl http://www.test.com

shell 脚本实现

#!/bin/bash  
  
step=2 #间隔的秒数,不能大于60  
  
for (( i = 0; i < 60; i=(i+step) )); do  
    $(php '/yourpath/test.php')  
    sleep $step  
done  
  
exit 0 
# m h  dom mon dow   command  
* * * * * /yourpath/crontab.sh

相关文章

网友评论

      本文标题:crontab

      本文链接:https://www.haomeiwen.com/subject/sdcncktx.html