(转,有改动)测试网页响应时间的shell脚本[需要curl支持]
用法及返回结果如下:
[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支持]的更多相关文章
- curl测试网页响应时间
连接时间: curl -s -o /dev/null -w "%{time_connect}\n" http://www.joinpay.com 传输时间: curl -s -o ...
- (转)shell脚本使用curl获取访问网站的状态码
curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com -I 仅测试HTTP头-m 10 最多查询10s-o /dev/null 屏蔽原 ...
- 《linux就该这么学》第五节课,shell脚本的各种语句!
第四章shell语句 (据课本和虚拟机实验排版,借鉴请改动) 4.2:shell脚本 脚本包括:脚本声明,脚本注释,脚本内容和命令 例:#!/bin/bash ...
- Linux系统——shell脚本
shell脚本编程 作用:通过命令行解析的方式,自动执行设定好的程序或命令代码.(若将脚本挂到定时任务中,就会自动在非工作时间里自动触发执行程序) Shell脚本文件以“.sh”结尾 规范的Shell ...
- Linux就该这么学--Shell脚本条件语句(一)
1.条件测试语句能够让Shell脚本根据实际工作灵活调整工作内容,例如判断系统的状态后执行指定的工作,或创建指定数量的用户,批量修改用户密码,这些都可以让Shell脚本通过条件测试语句完成. if条件 ...
- curl命令,curl实现post,curl监控网页shell脚本,curl多进程实现并控制进程数,
cURL > Docs > Tutorial: http://curl.haxx.se/docs/httpscripting.html 下载单个文件,默认将输出打印到标准输出中(STDO ...
- 如何进行shell脚本正确性测试
在实际工作中,需要对shell脚本进行正确性测试. 如何用最快最有效的方式进行测试? 很多开发的习惯是,二话不说,写完/拿到,就跑一把,看看输入,输出,想要的操作是否完成,也就过了. 其实这是十分不严 ...
- shell脚本进阶之条件测试与条件语句
接着上篇博客,今天整理一下关于条件测试和条件语句方面的知识. shell脚本进阶之条件测试 在编写shell脚本时,经常需要对一些条件进行判断,可以使用测试命令test辅助完成测试过程.t ...
- shell脚本中文件测试
shell脚本中文件测试 author:headsen chen 2017-10-17 14:35:19 个人原创,转载请注明作者,否则 依法追究法律责任 [ -f filename ] ...
随机推荐
- 纯灌水Linus主义
卖桃君重新整理了Linus的相关故事,在此摘选对自己有触动的内容. 关于生命的意义,李纳斯的解释是,有三件事具有生命的意义.它们是你生活当中所有事情的动机.第一是生存,第二是社会秩序,第三是娱乐.生活 ...
- mysql对表操作的各种语句
创建表 create table tb_user( id int(类型)primary key(设置为主键) auto_increment (设置id自增长), 每一个字段用逗号隔开, name va ...
- EasyUI-datagrid数据展示+MongoDB数据操作
使用EasyUI-datagrid进行数据展示:进行添加,修改,删除操作逻辑代码,数据源来自MongoDB. 一.新建SiteInfo控制器,添加Index页面:http://www.cnblogs. ...
- 操作系统笔记系列 一 Linux
学习资料: 1.http://www.icoolxue.com/ 马士兵 1.Linux 服务器端,目前98%的服务器都是Linux. 2.
- android 网络通讯
//get方式请求网络数据 String urlPath="http://192.168.98.112:8080/CloudMusicPlayer/fragment1_1_lv2/json/ ...
- jinfo命令的使用
jinfo命令 该命令可以打印出java进程的配置信息:包括jvm参数,系统属性等用法: jinfo [ option ] pid jinfo [ option ] executable core j ...
- 初识orcl
一.介绍基本数据库的端口号. SQLServer 端口号:1433 MySql 端口号:3306 Oracle ...
- TwentyTwenty – 使用 jQuery 实现图片对比功能
这是一款非常棒的图片对比工具,能够方便的应用到你的网站中.其基本思路是把两张图片层叠在一起,当你拖动滑竿的时候,利用 CSS clip 裁剪图片,进行形成视觉对比效果. 您可能感兴趣的相关文章 Met ...
- MySQL之MySQL5.7中文乱码
自己的MySQL服务器不能添加中文,于是自己使用 show variables like 'character%'; 查看了当前的编码格式 我又通过以下方法将其设置为utf-8 SETcharacte ...
- [deviceone开发]-viewShower和listView
一.简介 viewshower里嵌套listview,实现复杂的列表效果. 二.效果图 三.相关下载 http://source.deviceone.net/source-detail.html?do ...