获取CACTI RRD文件每天峰值的SHELL
2016-04-24 17:35
756 查看
代码如下:
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]#
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- Shell 脚本编程陷阱
- Cacti部署及常用插件安装
- shell字符串操作详解
- Shell中删除某些文件外所有文件的3个方法
- Ruby中执行Linux shell命令的六种方法详解
- VB使用shell函数打开外部exe程序的实现方法
- Shell编程的一些知识集合
- Shell中的for和while循环详细总结
- 什么是Shell?Shell脚本基础知识详细介绍
- Shell脚本中引用、调用另一个脚本文件的2种方法
- Shell脚本解压rpm软件包
- Linux Shell 数组建立及使用技巧
- Shell脚本实现复制文件到多台服务器的代码分享
- Shell脚本实现批量替换文件内容