公司服务器数据统计,求最大,最小,平均值!感谢william & james!!!- #!/bin/bash
- #定义日期时间
- date=`date -d yesterday +%Y%m%d`
- #下载mrtg产生的数据文件
- wget -O /mnt/$date-jboss1.txt &> /dev/null
- wget -O /mnt/$date-jboss2.txt &> /dev/null
- wget -O /mnt/$date-mysql.txt &> /dev/null
- #统计出数据中jboss、mysql的最大最小连接数
- cat /mnt/$date-jboss1.txt >> /mnt/$date-jboss2.txt
- #max1=`cat /mnt/$date-jboss1.txt | grep jboss | cut -d' ' -f2 | sort -un |grep -v ^$| tail -1`
- max2=`cat /mnt/$date-jboss2.txt | grep jboss | cut -d' ' -f2 | sort -un | grep -v ^$| tail -1`
- min1=`cat /mnt/$date-jboss1.txt | grep jboss | cut -d' ' -f2 | sort -unr |grep -v ^$| tail -1`
- min2=`cat /mnt/$date-jboss2.txt | grep jboss | cut -d' ' -f2 | sort -unr | grep -v ^$| tail -1`
- ##显示jboss最大、最小连接数
- #test "$max1" -ge "$max2" && echo max_j=$max1 || echo max_j=$max2
- #test "$min1" -lt "$min2" && echo min_j=$min1 || echo min_j=$min2
- echo max_j=$max2
- echo min_j=$min2
- s=0
- c=0
- for i in `cat /mnt/$date-jboss2.txt | grep jboss | cut -d' ' -f2| grep -v ^$`
- do
- let "s += $i"
- let "c += 1"
- done
- echo total=$s
- let "avg = $s/$c"
- echo average=$avg
- ##显示mysql最大、最小连接数
- echo max_m=`cat /mnt/$date-mysql.txt | grep mysql | cut -d' ' -f2 | sort -un | grep -v ^$| tail -1`
- echo min_m=`cat /mnt/$date-mysql.txt | grep mysql | cut -d' ' -f2 | sort -unr |grep -v ^$| tail -1`
修改后:
- #!/bin/bash
- #定义日期时间
- date=`date -d yesterday +%Y%m%d`
- #下载mrtg产生的数据文件
- wget -O /mnt/$date-jboss1.txt &> /dev/null
- wget -O /mnt/$date-jboss2.txt &> /dev/null
- wget -O /mnt/$date-mysql.txt &> /dev/null
- #统计出数据中jboss、mysql的最大最小连接数
- cat /mnt/$date-jboss1.txt >> /mnt/$date-jboss2.txt
- #max1=`cat /mnt/$date-jboss1.txt | grep jboss | cut -d' ' -f2 | sort -un |grep -v ^$| tail -1`
- max2=`cat /mnt/$date-jboss2.txt | grep jboss | cut -d' ' -f2 | sort -un | grep -v ^$| tail -1`
- min1=`cat /mnt/$date-jboss1.txt | grep jboss | cut -d' ' -f2 | sort -unr |grep -v ^$| tail -1`
- min2=`cat /mnt/$date-jboss2.txt | grep jboss | cut -d' ' -f2 | sort -unr | grep -v ^$| tail -1`
- ##显示jboss最大、最小连接数
- #test "$max1" -ge "$max2" && echo max_j=$max1 || echo max_j=$max2
- #test "$min1" -lt "$min2" && echo min_j=$min1 || echo min_j=$min2
- echo max_j=$max2
- echo min_j=$min2
- #显示jboss的平均值
- s=0
- c=0
- for i in `cat /mnt/$date-jboss2.txt | grep jboss | cut -d' ' -f2| grep -v ^$`
- do
- let "s += $i"
- let "c += 1"
- done
- let "avg_j = $s/$c"
- echo average_j=$avg_j
- ##显示mysql最大、最小连接数
- echo max_m=`cat /mnt/$date-mysql.txt | grep mysql | cut -d' ' -f2 | sort -un | grep -v ^$| tail -1`
- echo min_m=`cat /mnt/$date-mysql.txt | grep mysql | cut -d' ' -f2 | sort -unr |grep -v ^$| tail -1`
- #显示mysql的平均值
- x=0
- y=0
- for i in `cat /mnt/$date-mysql.txt | grep jboss | cut -d' ' -f2| grep -v ^$`
- do
- let "x += $i"
- let "y += 1"
- done
- let "avg_m = $x/$y"
- echo average_m=$avg_m
阅读(1506) | 评论(0) | 转发(0) |