代码如下:
url="/var/www/html/rra/150/9517.rrd
/var/www/html/rra/256/11345.rrd
/var/www/html/rra/150/9518.rrd"
fff=`echo $url | awk ‘{print NF}‘`
for((i=1;i<=3;i++))
do
criqi=`date +%s -d "2016-04-11 00:00:00"`
eriqi=`date +%s -d "2016-04-11 23:59:00"`
ccriqi=`echo "$criqi - 86400 * $i" | bc`
eeriqi=`echo "$eriqi - 86400 * $i" | bc`
dt=`date -d "1970-01-01 UTC $eeriqi seconds" +%F`
for((x=1;x<=$fff;x++))
do
uu=`echo $url | awk -v a=${x} ‘{print $a}‘`
/usr/local/rrdtool/bin/rrdtool fetch $uu MAX --start $ccriqi --end $eeriqi | sed -e ‘/^$/d‘ | grep -v "traffic_out" | awk ‘{printf "%f\n",$2}‘ | sed ‘s/\-nan/0.0000000000e+00/g‘ >> /tmp/test${x}
done
ff=`cat /tmp/test1 | wc -l`
for((n=1;n<=$ff;n++))
do
for((y=1;y<=$fff;y++))
do
tt=`cat /tmp/test${y} | sed -n ${n}p`
echo $tt >> /tmp/fud
done
aa=`cat /tmp/fud | awk ‘{sum+=$0}END{print sum}‘`
re=`echo "$aa" | awk ‘{sum=$0*8/1000000}END{printf "%.2f",sum}‘`
echo $re >> /tmp/testz
rm -rf /tmp/fud
done
td=`cat /tmp/testz | sort -nr | sed -n 1p`
if [ `echo "$td > 1000"|bc` -eq 1 ];then
tpt=`echo "scale=3;$td / 1000" | bc | awk ‘{printf "%.2f",$0}‘`
echo $tpt"G" $dt
echo "$tpt"G" $dt" >> /root/qz.txt
else
echo $td"M" $dt
echo "$td"M" $dt" >> /root/qz.txt
fi
for((b=1;b<=$fff;b++))
do
rm -rf /tmp/test${b}
done
rm -rf /tmp/testz
done;运行结果如下:
[root@cacti]# sh get_in 2.35G 2016-04-10 3.69G 2016-04-09 6.84G 2016-04-08 [root@cacti]#
原文:http://flyingzf.blog.51cto.com/38414/1767273