`

(转)测试网页响应时间的shell脚本[需要curl支持]

阅读更多

用法及返回结果如下:
lvyaozu@lvyaozu-desktop:~/shell$ ./requesturl.sh -n20 http://www.baidu.com
Request url: http://www.baidu.com
Request number: 20
Request Failed: 0
——Average Value——
time_connect: 0.1614
time_total: 0.1693
time_namelookup: 0.0088
————————-
请求参数:
-n 指定发送多少次请求,默认为10

返回结果为 curl -w 选项返回值,以下摘自curl官方文档:

http://curl.haxx.se/docs/manpage.html

time_connect The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
time_total The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.
time_namelookup The time, in seconds, it took from the start until the name resolving was completed.

 

 

 

#!/bin/bash
#requesturl.sh
 
usage="
Usage: $0 [options...] <url>\n
Options:\n
 -h This help text\n
 -n <num> The numbers to request\n
"
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"\n"
    i=$[$i+1]
done
#echo -e $s
echo -e $s | \
awk '{OFS="\n"}{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 "\n------Average Value------"; \
    for(i in result) {print i ": " result[i]/num;} \
    print "-------------------------"}'
 

 

 

 

 

分享到:
评论

相关推荐

    cURL操作Openstack对象存储的ReST API详解

    由于最近工作需要使用Openstack ,使用cURL操作...cURL允许你从命令行或shell脚本传送和接收HTTP的请求和响应。这使得直接与ReST的API工作而无需其他客服端APIs成为可能。本文,我们需要使用到以下的cURL命令行选项:

    seeyonAjaxGetshell:致远OA seeyon未授权漏洞批量getshell

    抄借鉴tools论坛大佬的payload写了个批量拿shell的脚本。 Note: 为了方便(懒比)直接调用curl,因此请在Linux下运行。 ip.txt --&gt; 待检测IP shell.txt --&gt; shell shell: 密码:rebeyond 冰蝎3连接 2020年1月9...

    hacking-on-deis-workshop:在 AWS 上自定义 Deis 集群的研讨会

    使用官方安装shell脚本: curl -sSL https://get.docker.com/ | sh curl -sSL https://get.docker.com/ | sh 要查看脚本的作用,请查看 大多数发行版在他们的包存储库中有一个太旧版本的 Docker -

    pagicurl:为JSON端点分页curl结果

    该脚本包装curl,并在分页标题之后进行成功调用。 使用此处定义的链接标题: : 仅适用于json响应类型 像curl一样工作,并接受所有标志,但要求uri优先。 调用此: $ ./pagicurl ...

    respond2png:一个简单的 bash 脚本,用于创建响应式设计的多个屏幕截图

    一个简单的 bash 脚本,用于创建响应式设计的多个屏幕截图。 需要 。 安装 $ curl ...

    narodmon-openwrt-script:用于将数据发送到narodmon服务器的脚本

    narodmon-openwrt-script 用于将数据发送到narodmon服务器的脚本设备:D-Link DIR-825 固件:OpenWrt Chaos Calmer 15.05.1 必需的软件包:owserver,owshell,bc,curl 该脚本从连接的传感器收集数据(例如,温度)...

    solr-monitor:监视Solr复制运行状况的简单脚本

    依赖项:curl,xmllint,xmlstarlet。 在Linux和OS X上测试过Solr 4.1 API。 默认情况下,它将在端口8983上的localhost中检查Solr内核,并且复制容限为15分钟。 这意味着,如果从属内核位于主控之后,并且在15分钟...

    PulseEffects-Presets:PulseEffects 预设集合

    脉冲效果预设 预设集合 它目前包含: 低音增强 + 完美均衡 此预设基于与 Razor sorround 脉冲响应相结合。 完美的情商 此预设仅启用 升压 此预设基于均衡器设置,特别是增强低频 ... 注意:脚本需要安装curl 。 Ubu

    node-exec-sync:重要的

    重要说明:该存储库不再维护。 现在,节点v0.12内置了相同的功能: ://nodejs.org/api/child_process.... 请勿将其用于常规服务器代码,否则将破坏服务器的响应能力。 var execSync = requ

    crew-mates-main.zip

    船员伴侣强大的脚本集,可自动管理,部署和保持任务关键型应用程序的运行。依存关系安装curl -o- https://raw.githubusercontent.com/GreenCubeIO/crew-mates/latest/install.sh | bash关于这个项目作为开发人员,您...

Global site tag (gtag.js) - Google Analytics