用法及返回结果如下:

[root@myserver01 tmp]# sh test_web.sh -n500 http://www.baidu.com
Request url: http://www.baidu.com
Request number:
Request Failed:
------Average Value------
time_connect: 0.014414
time_namelookup: 0.010926
time_total: 0.020486
-------------------------

请求参数:
-n 指定发送多少次请求,默认为10

返回结果为 curl -w 选项返回值,以下摘自curl官方文档(http://curl.haxx.se/docs/manpage.html):

time_connect :连接时间,从开始到建立TCP连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个time_connect时间减去前边time_namelookup时间。(The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.)

time_namelookup: DNS解析时间,从请求开始到DNS解析完毕所用时间。(The time, in seconds, it took from the start until the name resolving was completed.)

time_total: 总时间,按秒计。精确到小数点后三位。 (The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.)

代码如下(可自行添加其他功能):

#!/bin/bash
#requesturl.sh usage="
Usage: $ [options...] <url>\n
Options:\n
-h This help text\n
-n <num> The numbers to request\n
"
if [ $# -lt ]
then
echo -e $usage
exit
fi
num=
while getopts "n:h" arg
do
case $arg in
n)
num=$OPTARG
if [ $num -lt ]
then
num=
fi
;;
h)
echo -e $usage
exit
;;
?)
echo "Unknow argument"
exit
;;
esac
done url=$(eval echo "\$$#") if [ "http://" != ${url::} ]
then
echo "The url need to add the http:// prefix"
exit
fi echo "Request url: "$url
echo "Request number: "$num i=
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+]
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= \
'{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 "-------------------------"}'

(转自:http://renxiangzyq.iteye.com/blog/782773)

(转,有改动)测试网页响应时间的shell脚本[需要curl支持]的更多相关文章

  1. curl测试网页响应时间

    连接时间: curl -s -o /dev/null -w "%{time_connect}\n" http://www.joinpay.com 传输时间: curl -s -o ...

  2. (转)shell脚本使用curl获取访问网站的状态码

    curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com -I 仅测试HTTP头-m 10 最多查询10s-o /dev/null 屏蔽原 ...

  3. 《linux就该这么学》第五节课,shell脚本的各种语句!

    第四章shell语句 (据课本和虚拟机实验排版,借鉴请改动)               4.2:shell脚本   脚本包括:脚本声明,脚本注释,脚本内容和命令 例:#!/bin/bash      ...

  4. Linux系统——shell脚本

    shell脚本编程 作用:通过命令行解析的方式,自动执行设定好的程序或命令代码.(若将脚本挂到定时任务中,就会自动在非工作时间里自动触发执行程序) Shell脚本文件以“.sh”结尾 规范的Shell ...

  5. Linux就该这么学--Shell脚本条件语句(一)

    1.条件测试语句能够让Shell脚本根据实际工作灵活调整工作内容,例如判断系统的状态后执行指定的工作,或创建指定数量的用户,批量修改用户密码,这些都可以让Shell脚本通过条件测试语句完成. if条件 ...

  6. curl命令,curl实现post,curl监控网页shell脚本,curl多进程实现并控制进程数,

    cURL > Docs > Tutorial:  http://curl.haxx.se/docs/httpscripting.html 下载单个文件,默认将输出打印到标准输出中(STDO ...

  7. 如何进行shell脚本正确性测试

    在实际工作中,需要对shell脚本进行正确性测试. 如何用最快最有效的方式进行测试? 很多开发的习惯是,二话不说,写完/拿到,就跑一把,看看输入,输出,想要的操作是否完成,也就过了. 其实这是十分不严 ...

  8. shell脚本进阶之条件测试与条件语句

       接着上篇博客,今天整理一下关于条件测试和条件语句方面的知识. shell脚本进阶之条件测试    在编写shell脚本时,经常需要对一些条件进行判断,可以使用测试命令test辅助完成测试过程.t ...

  9. shell脚本中文件测试

    shell脚本中文件测试 author:headsen chen  2017-10-17  14:35:19 个人原创,转载请注明作者,否则 依法追究法律责任 [ -f  filename  ]   ...

随机推荐

  1. Redis配置集群一(window)

    因为接下来的项目要使用到redis作为我们项目的缓存,所以就花了一天时间研究了一下redis的一些用法,因为没转linux虚拟机,所以就决定先研究一下windows版本的redis集群.主要是redi ...

  2. python不用加号实现加法

    问题: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.E ...

  3. SQL join中on与where区别

    本文导读: 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户.例如在使用left jion时,on条件是在生成临时表时使用的条件,它不管on中的条件是否 ...

  4. synchronized的实现原理-java并发编程的艺术读书笔记

    1.synchronized实现同步的基础 Java中的每个对象都是可以作为锁,具体有3种表现. 1.对于普通同步方法,锁是当前实例对象. 2.对于静态同步方法,锁是当前类的Class对象. 3.对于 ...

  5. Linux IO函数的使用和区别

    Linux系统中的IO函数主要有read.write.recv.send.recvmsg.sendmsg.readv.writev,本篇主要介绍他们的使用以及区别. read函数: #include ...

  6. JavaScript中数组的增删改查

                                               数组的增加 ary.push()   向数组末尾添加元素,返回的是添加后新数组的长度,原有数组改变 ary.uns ...

  7. Ajax关于readyState(状态值)和status(状态码)的研究

    var getXmlHttpRequest = function () { try{ //主流浏览器提供了XMLHttpRequest对象 return new XMLHttpRequest(); } ...

  8. hybird之web动态换肤实现

    前言 最近在重构个hybird(原生的壳包着Web页面)的UI框架,进行到了做换肤功能的阶段,所以这里是我思考的解决的方法. 预想 目前实现换肤的功能无非就两种做法. 1.写几个皮肤文件,然后切换使用 ...

  9. Javascript到PHP加密通讯的简单实现

    其实内容主要来源于上一篇博文,只是重新组织了语言,并做了原理性的阐述,更容易理解:P ----------------------------------------- 华丽的分割线 -------- ...

  10. Android studio 如何查看当前git 分支的4种方式

    1.第一种       2.第二种       3.第三种 4.第四种       前面3种都是通过android studio 操作的. 第四种是通过命令行操作.(可以在 git bash 中输入命 ...