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

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

相关推荐