【工作经历:阿里巴巴搜索技术研发中心QA ,百度新产品测试部QA】 【领域:测试分析,自动化测试,性能测试,安全测试 】 【个人定位:高级测试工程师+培训师+领域产品专家】

shell之函数式脚本

上一篇 / 下一篇  2009-03-06 22:31:28 / 个人分类:Linux

自己最近纯粹吃饱撑的了。
想把多个性能测试的case用脚本去实现。
目前已经实现了大部分了。只差一点点了。

不止一次的问自己,真的是没有必要。自己越来越懒了。
越来越依赖自己的脚本了。

发现了写脚本的一个非常不错的方法。
采用函数编程。

      gexec $search_list $proxy_list  logsave 2>&1 |tee logsave.txt #save log #去所有的searchproxy上去保存日志

可以在每个机器上,修改启动脚本,增加关于logsave的定义,实现不同角色的个性定义。

发现这个方法非常的棒,解决了不少问题,记录一下。

abenchloadm()

{

         [ $# -eq 0 ]&&echo "abenchloadm paramters ip port datadir

         example abenchload  -s 7200 -p 18 -k 119.42.239.38 2312 offer_url"&&return||echo "OK,start abench"

         [[ `echo $*|grep "\-p"` ]]&&(echo $*|grep "\-k"&&print "OK,-p with -k"||print "Be carefull , no -k")

         #all the history operations would be record in the abench.log , you can use it to check history .

         seven #reload seven.sh and $USER.sh

         abench_log=abench.log

         now=`date +%Y%m%d%H%M`

         #show the start time and parameters and save them to abench.log

         echo $*

         echo "Start at $now

         $* " >>$abench_log

         #invoke abench and give it the parameters

         abench -l abench_$now.log $*  2>&1|tee abench_$now

         timestop=`date +"%m/%d/%Y %H:%M"`

         echo "End at `date +%Y%m%d%H%M`    " >>$abench_log

         #get the time and format it for simon

         timestart="${now:4:2}/${now:6:2}/${now:0:4} ${now:8:2}:${now:10}"

         #invoke report function for get the urls of simon and some basic infomation

         reportm "$timestart"  "$timestop"  >report_${now}.htm  #生成相关simon图报告,此函数不同之前的report,它可以提供机器列表的资源占用信息,比如cpumemuser之类的,并统计出search的平均指标作为参考。

         echo start save log

         gexec $search_list $proxy_list  logsave 2>&1 |tee logsave.txt #save log #去所有的searchproxy上去保存日志

         echo start get config

         gexec $search_list $proxy_list  '{ cd $install_dir/etc; getconfig;check root=; } ' > config.txt 2>&1 #check config #去所有机器上收集配置信息,以备检查。

         echo start check log

         glogcheck|uniq -c > logcheck.txt  2>&1 #check log #去所有机器上分析日志

         #mail you the result by attachments

         echo start send mail

         echo "$*"|mutt -s AT@`hostname` -a abench_$now -a report_${now}.htm -a logsave.txt -a logcheck.txt -a config.txt $mail_addr #发送所有结果到你的工作信箱

         #if you setted the mobie_mail var , it will notice you by a sms

         if [[ -n $mobile_mail ]]   #设置手机邮箱的话,就发短信提醒。

         then

                   qps="qps=`cat abench_$now|grep "query per second"|awk -F: '{print $2}'`"

                   art="art=`cat abench_$now|grep "average response time"|awk -F: '{print $2}'`"

                   echo "`cat abench_$now` "|mutt -s "$qps $art cmd abenchloadm $*"  $mobile_mail

         fi

}

 




TAG:

 

评分:0

我来说两句

Open Toolbar