discover_disk.sh感知disk

  sre

5fcc6d6d25dc97282.jpg_fo742.jpg

#! /bin/bash

Disks=`df -h | awk '{a[NR]=0}END{for(i=2;i<=NR;i++)print a[i]}'`
# awk 'BEGIN{sum=0}{sum+=1}END{print sum}' 
i=1
parent=
capacity=0
disksize=0

function size(){
    disksize=`echo 1 | tr -cd "[0-9,.]"`
    unit=`echo1 | sed 's/[0-9,.]//g'`
    if [[ unit == "T" ]];then
          #disksize=`echodisksize*1024*1024 | bc`
          disksize=(echodisksize |awk '{ printf "%0.2f\n" ,1*1024*1024}')
     fi
    if [[unit == "G" ]];then
         #disksize=`echo disksize*1024 | bc`
         disksize=(echo disksize |awk '{ printf "%0.2f\n" ,1*1024}')
     fi
    if [[ unit == "M" ]];then
        #disksize=`echodisksize | bc`
        disksize=(echodisksize |awk '{ printf "%0.2f\n" ,1}')
    fi
}

for property inDisks
do
    case i in        1)
            str="str,'cpname':'disk'"
            str="str,'filesystem':'property'"
        ;;
        2)
            size property
            str="str,'capacity':'disksize'"
        ;;
        6)
            str="str,'path':'property'"
        ;;
    esac       i=((i+1))
    t=((i%7))
    if [t = 0 ];then
        str="str,'os':'linux','name':'(linux)硬盘监控模板'"
        str="{str#*,}"
        parent="parent{str},"
        str=
        i=1
    fi
done

result="[{parent%,*}]"
result=`echo{result//\'/\"}`
echo $result





LEAVE A COMMENT

Captcha Code