Crond服务+Shell实现秒级任务

服务

[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实现秒就很简单了。

 


作者:Godtoy
链接:https://www.jianshu.com/p/2dcda651c94d
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

转载于:https://www.cnblogs.com/gongxianjin/p/11266072.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值