Shell测试性能相关脚本

  利用传递参数的形式对当前的内容进行测试

#!/bin/sh
Interval=5
A=1000
Free=`cat /proc/meminfo|grep "MemFree" | awk '{print $2}'`
if [ ! -f "pidconf" ]       
then
    echo "FILE pidconf NOT FOUND!"
    exit
fi
if [ ! -f "result" ]     #不存在result这个file就touch一个
then
    touch result
fi
if [ ! -d "pidbak" ]     #如果不存在pidbak这个目录directory就创建pidbak这个目录
then
   mkdir pidbak
fi
mv pidfile/* pidbak       
while [ 1 ]
do
echo "`date`" >> result
while read line
do 
if [ ! -f "pidfile/$line" ]
then
touch pidfile/$line 
old=`pgrep $line`
new=$old
echo "$old" > pidfile/$line
else
old=`cat pidfile/$line`
new=`pgrep $line`
if [ $? != 0 ]
then
new="NULL"
fi
fi
if [ ${old} != ${new} ]
then
echo "===ERROR===[$line] pid change, [$old=>$new]" >> result
echo "$new" > pidfile/$line
else
echo "==SUCCESS==[$line=$new]" >> result
fi
done < pidconf


sleep 10
Free1=`cat /proc/meminfo|grep "MemFree" | awk '{print $2}'`
T=`expr $Free - $Free1`
if [ $T -le $A ]
then
echo "========memory normal======" >> result
else
echo "========memory leak========" >> result
fi
if [ $# != 1 ];then
    echo "wrong parameter!"
    exit 1
fi
checktime=$1
check=1
allcpu=0
maxcpu=0
mincpu=100
while [ $check -le $checktime ]
do
    docpu=`cpu -c 1`
    cucpu=`echo $docpu | cut -b 11-14 | cut -d \% -f 1`
    if [ $cucpu -gt $maxcpu ];then
        maxcpu=$cucpu
    fi
    if [ $cucpu -lt $mincpu ];then
        mincpu=$cucpu
    fi
    allcpu=`expr $allcpu + $cucpu`
    avcpu=`expr $allcpu / $check`
    echo "Average:$avcpu%  Now:$docpu"
    check=`expr $check + 1`
done
echo "MAX CPU: $maxcpu%  MIN CPU: $mincpu%" >> result
echo "" >> result
sleep $Interval
done

  

 

 

 

 

#!/bin/sh
echo "Read Config..."
while read line;
do
    eval "$line"
done < perfConf
cat perfConf
echo "Read Config Successfully!"
echo "Ip Test..."
if [ $Protocol == "UDP" ]
then
    iperf -c $Ip -u -t 1 > connectData 2>&1
else
    iperf -c $Ip -t 1 > connectData 2>&1
fi
if [[ `grep -c "failed" connectData` -eq "1" ]]
then
    echo "ERROR:iperf server can not connect"
    exit 0
	fi
	echo "Ip Test Successfully!"
	function rand()
{
    min=$1
    max=$(($2-$min+1))
   #num=$(tr -cd 1-9 < /dev/urandom 1 | head -c 10)
    num=$(tr -cd 1-9 < /proc/sys/kernel/random/uuid 1 | head -c 10)
    echo $(($num%$max+$min))
}

if [[ $Mode == "Auto" ]]
then
    myloop=1
    echo "Begin to Auto Test..."
    echo ""
    while [ $myloop -le $Loop ]
    do
	echo "==="`date`"==="
        echo "===NO."$myloop" Loop==="
        if [[ $Protocol == "UDP" ]]
        then
            len=$(rand $Start_Len $End_Len)
            bd=$(rand $Start_Bandwidth $End_Bandwidth)"K"
            echo "iperf -c "$Ip" -t "$CircleTime" -u -b "$bd" -l "$len" -p "$Port" -i "$Interval
                iperf -c $Ip -t $CircleTime -u -b $bd -l $len -p $Port -i $Interval
        else
            echo "iperf -c "$Ip" -t "$CircleTime" -i "$Interval" -p "$Port
            iperf -c $Ip -t $CircleTime -i $Interval -p $Port
        fi
        let myloop=myloop+1
        echo "=============================="
        echo ""
        sleep $SleepTime
    done
	else
    echo "Begin to Passive Test..."
    if [[ $Protocol == "UDP" ]]
    then
        iperf -c $Ip -t $Time -u -b $Bandwidth -i $Interval
    else
	iperf -c $Ip -t $Time  -i $Interval
    fi
fi

  

 

posted @ 2020-07-08 11:24  陈晓猛  阅读(360)  评论(0编辑  收藏  举报