#!/bin/bash
#说明函数定义脚本
#***************************************************************
#函数 status_check
#判断程序$1是否已经在运行 $1:第一个参数
#***************************************************************
function status_check()
{
pids=`ps aux|grep -w ${1}|grep -v grep|awk '{print $2}'|head -1` #获取${1}进程号grep -w ${1}:匹配第一个参数单词的行;grep -v grep:去掉含grep的行,awk '{print $2}':取行的第二列(进程号),head -1:(多个同名进程时)只取第一行
#pids=pidof ${1}|awk '{print $1}' #获取${1}进程号,awk '{print $1}' 有多个同名的进程时,取第一个(第一列)
if [ ${pids} ]
then
echo ${1}' running'
return 1
else
echo ${1}' not running'
return 2
fi
}
#
#***************************************************************
#函数 stop()
#停止$1
#***************************************************************
function stop()
{
TRY=1
while true; do
status_check ${1}
if [ $? -ne 1 ] #-ne:不等于
then
echo ${1}' stoped'
break
else
ps aux|grep -w ${1}|grep -v grep|awk '{print $2}'|xargs kill -15 #-w ${1} 仅完全匹配字词${1}(既参数1),grep -v grep”是在列出的进程中去除含有关键字“grep”的进程,awk '{print $2}'取行的第二列(进程号),
#“xargs kill -15”中的xargs命令是用来把前面命令的输出结果(PID)作为“kill -15”命令的参数,并执行该命令。kill发信号-15给进程,进程释放资源后退出,发-9给进程则强制退出
echo ' stop ' ${1}
fi
sleep 5
done
}
#--------------------------------------------------------------------------
TEST_NUM=3
ONE_RESULT="./test_one_relt.txt"
RESULTS="./test_relt.txt"
FIND_STR="Total op"
CHECK_INTERVAL=5
waittime=0
for((i=1;i<=${TEST_NUM};i++))
do
waittime=0
echo "现在时间:`date '+%Y-%m-%d %H:%M:%S'`"
echo "NO.${i} test start."
rm -rf ${ONE_RESULT}
./ceph_perf_msgr_client 172.17.31.54:12345 1 1 100 10 40960 &> ${ONE_RESULT} &
while [[ `grep -c "${FIND_STR}" ${ONE_RESULT}` -eq '0' ]]; do
echo "Test not finished,continue to wait. ${waittime}s"
sleep ${CHECK_INTERVAL}
((waittime+=${CHECK_INTERVAL}))
done
echo "NO.${i} test finished."
cat ${ONE_RESULT} >> ${RESULTS}
stop ceph_perf_msgr_client
echo " "
echo " "
done
cat ${RESULTS} |grep 'run time'
((i--))
echo "${i}/${TEST_NUM} Test finished."
08-23
512
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-28