zoukankan      html  css  js  c++  java
  • 判断网站响应时间 脚本

    只适用与域名访问:

    #!/bin/bash
    #requesturl.sh

    usage="
    Usage: $0 [options...] <url>
    Options:
    -h This help text
    -n <num> The numbers to request
    "
    if [ $# -lt 1 ]
    then
        echo -e $usage
        exit 1
    fi
    num=10
    while getopts "n:h" arg
    do
        case $arg in
            n)
                num=$OPTARG
                if [ $num -lt 1 ]
                then
                    num=1
                fi
                ;;
            h)
                echo -e $usage
                exit 1
                ;;
            ?)
                echo "Unknow argument"
                exit 1
                ;;
            esac
    done

    url=$(eval echo "$$#")

    if [ "http://" != ${url:0:7} ]
    then
        echo "The url need to add the http:// prefix"
        exit 1
    fi

    echo "Request url: "$url
    echo "Request number: "$num

    i=1
    while [ $i -le $num ]
    do
        c=`curl -o /dev/null -s -w
            "http_code:%{http_code} time_namelookup:%{time_namelookup}
            time_connect:%{time_connect} time_total:%{time_total}" $url`
        s=$s$c" "
        i=$[$i+1]
    done
    #echo -e $s
    echo -e $s |
    awk '{OFS=" "}{if($1) for(i=1;i<=NF;i++)print $i}' |
    awk -F: -v num=$num -v failnum=0
        '{if($1 != "http_code")result[$1]+=$2;if($1=="http_code" && $2 != 200)failnum++}
        END{print "Request Failed: " failnum " ------Average Value------";
        for(i in result) {print i ": " result[i]/num;}
        print "-------------------------"}'

    验证: sh 1.sh  -n3 http://www.baidu.com

  • 相关阅读:
    numpy 笔记
    xdoj 1402 XY之说走就走的旅行
    红黑树 (洛谷 P3369 【模板】普通平衡树 )
    AVL树 (PAT甲级 Is It a Complete AVL Tree )
    xdoj-1297 Tr0y And His Startup
    C# 获取当前路径7种方法
    JQuery常用方法一览
    Jquery 处理字符串
    js 获取参数
    js cookie
  • 原文地址:https://www.cnblogs.com/yueminghai/p/6564925.html
Copyright © 2011-2022 走看看