码迷,mamicode.com
首页 > Web开发 > 详细

shell 函数法实现监控web 网站url

时间:2017-06-03 00:52:02      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:shll function

使用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]#


本文出自 “知识改变命运” 博客,请务必保留此出处http://ahtornado.blog.51cto.com/4826737/1931787

shell 函数法实现监控web 网站url

标签:shll function

原文地址:http://ahtornado.blog.51cto.com/4826737/1931787

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!