输入端口和需要运行的命令,就可以进行端口对应的页面检测,为检测到则运行某个命令启动。
bash# vim easy_probe.sh
#!/bin/bash
# 第一参数,检测的端口
# 第二参数,启动服务的命令
count=0
for varible1 in {1..5}
do
curl -s http://121.196.181.84:$1/1.html >/dev/null
# 如果执行失败,则加1
if [ $? -ne 0 ];then
let count+=1
fi
sleep 3
done
# 检测5次,都没成功,则说明服务挂了。
echo $count
if [ $count -eq 5 ];then
nohup $2 &
echo "启动$1成功"
fi
# sleep 3 表示3s检测一次,
# 1.html 为专用检测页面,如果可以访问,怎说明该应用ok的,
# 运行 bash easy_probe.sh 80 nginx
#
本文作者:mykernel
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!