使用shell 函数实现监控web 网站url
[root@linux-node3 scripts]# cat checkweb.sh
#!/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."
else
echo "$1 is no."
fi
}
function main() {
if [ $# -ne 1 ]
then
usage
fi
check_url $1
}
main $*脚本运行如下
[root@linux-node3 scripts]# sh checkweb.sh usage:checkweb.sh url [root@linux-node3 scripts]# sh checkweb.sh www.baidu.com www.baidu.com is yes. [root@linux-node3 scripts]# sh checkweb.sh www.baidu89988.com www.baidu89988.com is no. [root@linux-node3 scripts]#
转载于:https://blog.51cto.com/ahtornado/1931787
本文介绍了一个简单的Shell脚本,用于监控指定URL的状态。通过使用wget工具进行静默访问并判断返回状态来检查网站是否可达。如果URL有效则输出肯定结果,否则输出否定结果。
1万+

被折叠的 条评论
为什么被折叠?



