良许Linux教程网 干货合集 Linux中通过shell脚本监测网站状态

Linux中通过shell脚本监测网站状态

linux系统运维过程中,经常会遇到些问题,有时候问题会比较麻烦,此时shell脚本的优势就体现出来,本篇文章重点为大家讲解一下Linux中通过shell脚本监测网站状态。

shell脚本检查网站是否正常shell脚本检查网站是否正常

其一

#!/bin/bash
function usage(){
echo $"usage:$0 url"
exit 1
}

function check_url() {

wget --spider -q -o /dev/null --tries=1 -T 5 $1
if [ $? -eq 0 ]
then
echo "$1 is yes."
exit 0
else
echo "$1 is fail."
exit 1
fi
}

其二

#!/bin/bash
. /etc/init.d/functions
num=`curl -I -m 5 -s -w "%{http_code}\n" -o /dev/null 192.168.100.141:8080`
if [ $num -eq 200 ]
then action "ok!" /bin/true
else action "failure" /bin/false
fi

其三

. /etc/init.d/functions
curl -s -o /dev/null 192.168.100.141:8080
if [ $? -eq 0 ]
then action "Web site access is normal" /bin/true
else action "Failure of website access" /bin/false
fi

其四

#!/bin/bash
. /etc/init.d/functions
wget --spider -T 5 -q -t 2 192.168.100.141:8080

if [ $? -eq 0 ]
then action "Web site access is normal" /bin/true
else action "Failure of website access" /bin/false
fi

以上就是良许教程网为各位朋友分享的Linu系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

img
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部