shell:统计周期时间内磁盘的写带宽总量

 1 #!/bin/bash
 2 # 作用:统计周期时间内磁盘的写带宽总量
 3 
 4 let aDay=24*3600  #一天多少秒
 5 startTime=$(date +%s)
 6 nohup iostat -mxt 1 >output & 
 7 count=0  #记录次数
 8 circle=7  #循环统计周期,这里为一周
 9 sum=0  #一个周期内的写带宽总量
10 
11 while  true 
12 do
13     if [ "$count" -eq "$circle" ];then
14         printTime=$(date +%Y/%m/%d-%H:%M:%S)
15         echo -e "$printTime The result of a week is $sum MB 
" >> totalWriteSize.out
16         count=0
17         sum=0
18     else
19         nowTime=$(date +%s)
20         let diffTime=nowTime-startTime
21         if [ "$diffTime" -ge "$aDay" ];then
22             sum_day=`awk '/nvme0n1/ {sum_day += $7};END {print sum_day}' output`  #将文件output中有sda行的第7列值求和
23             sum=$(echo "scale=2; $sum+$sum_day"  | bc)   #一个周期内的写带宽总量
24             printTime=$(date +%Y/%m/%d-%H:%M:%S)
25             echo -e "$printTime The result of a day is $sum_day MB 
" >> totalWriteSize.out
26             cp output output"$count"
27             echo > output
28             let count++
29             startTime=$nowTime
30         fi
31         sleep 1
32     fi
33 done
原文地址:https://www.cnblogs.com/seaBiscuit0922/p/7511465.html