`
喜欢蓝色的我
  • 浏览: 370409 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

shell 实现查找磁盘占用超标

 
阅读更多

#!/bin/bash
diskspaces=($(df -hP | grep /dev | awk '{print$1,$5}' | sed 's/%//g'))
for ((i=0;i<${#diskspaces[*]};i++));do

    echo -e "${diskspaces[$i]}\n"
#查找出{diskspaces}中百分比数字
    if((i%2 ==1));then
        echo -----------------------
        echo -e $i
        echo -e ${diskspaces[$i]}
        #temp=${values[i]}

        disk_values=${diskspaces[i]}

#查找disk值超过10的磁盘
        if [ $disk_values -gt 10 ];then
            #echo -e "disk_value: ${disk_values}\n"
            echo -e "${diskspaces[$i-1]}:${disk_values}\n"

#字符变量连接
            message=${diskspaces[$i-1]}${disk_values}
            echo -e "message: ${message}"
        fi

        continue


    fi

done

 

 

------------------------------------------------------------------------------------------------

运行结果:取出所有磁盘占用超过10%,磁盘路径及百分比

[root@vm-156-223-dev03-hp letv]# sh monitor01.sh
/dev/mapper/VGSYS-lv_var

58

-----------------------
1
58
/dev/mapper/VGSYS-lv_var:58

message: /dev/mapper/VGSYS-lv_var58
tmpfs

0

-----------------------
3
0
/dev/vda1

19

-----------------------
5
19
/dev/vda1:19

message: /dev/vda119
/dev/mapper/VGSYS-lv_root

17

-----------------------
7
17
/dev/mapper/VGSYS-lv_root:17

message: /dev/mapper/VGSYS-lv_root17
/dev/mapper/VGSYS-lv_letv

10

-----------------------
9
10

-------------------------------------------------------------------------------------------------------------------

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics