#!/bin/sh
. /etc/init.d/functions
function checkURL()
{
checkUrl=$1
echo ‘check url start ...‘
judge=($(curl -I -s --connect-timeout 2 ${checkUrl}|head -1|tr "\r" "\n"))
if [ "${judge[1]}" == ‘200‘ -a "${judge[2]}" == ‘OK‘ ] #判断http状态码且字符为OK
then
action "${checkUrl}" /bin/true
else
action "${checkUrl}" /bin/false
echo -n "retrying again...";sleep 3;
judgeagain=($(curl -I -s --connect-timeout 2 ${checkUrl}|head -1|tr "\r" "\n"))
if [ "${judgeagain[1]}" == ‘200‘ -a "${judgeagain[2]}"==‘OK‘ ]
then
action "${checkUrl},retried again" /bin/true
else
action "${checkUrl},retried again" /bin/false
fi
fi
sleep 1;
}
#usage method
checkURL www.baidu.com
相关文章
- 11-09Liunx Shell编程入门----编写简单的开机欢迎脚本与操作服务脚本
- 11-094-3 调试代码命令 scrapy shell http://blog.jobbole.com/114496/(入口url)
- 11-09Shell入门,关于语法的一些简单玩意儿
- 11-09正则简单操作cookie、url search
- 11-09python定义的一个简单的shell函数的代码
- 11-09自动化运维:(3)写一个简单的Shell脚本(案例)
- 11-09metasploit简单使用-生成木马反弹shell连接
- 11-09嵌入式实操----基于RT1170移植lwshell库实现简单的shell功能(九)
- 11-09简单介绍url的格式 协议、端口、路径、参数(params)、查询(query)、片段(frag)、url编码
- 11-09shell 简单的比大小脚本