美文网首页
Crond服务+Shell实现秒级任务

Crond服务+Shell实现秒级任务

作者: Godtoy | 来源:发表于2017-02-08 17:30 被阅读0次

服务

[root@19-v1-centos-6 ~]# chkconfig --list | grep crond
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off

查看任务

[root@19-v1-centos-6 ~]# crontab -l
*/1 * * * * sh /server/scripts/task_start.sh

编辑任务

[root@19-v1-centos-6 ~]# crontab -e

Shell 脚本

[root@19-v1-centos-6 ~]# mkdir -p /server/scripts/
[root@19-v1-centos-6 ~]# mkdir -p /server/logs/

脚本内容

#! /bin/bash
task_url=("http://192.168.32.1/task.php/task/check_order" "http://192.168.32.1/task.php/task/check_robot_online")
for n in `seq 10`
do
     for task in ${task_url[*]}
     do
        curl $task  >> /server/logs/task.log
     done
     sleep 6
done

这个脚本其实就是已秒级去请求shell,如果shell去做后台运行加&,可能会死掉,重启也没有了,but crond最低是分级别的任务,所以crond+shell实现秒就很简单了。

相关文章

网友评论

      本文标题:Crond服务+Shell实现秒级任务

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