发现磁盘的shell

#!/bin/bash
#set -x
diskarray=(`cat /proc/diskstats |grep -E "\bsd[a-z]\b|\bxvd[a-z]\b|\bvd[a-z]\b"|awk '{print $3}'|sort|uniq  2>/dev/null`)

length=${#diskarray[@]} ##diskarray[@] --->数组diskcarray的个数
printf "{\n"
printf  '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
        printf '\n\t\t{'
        printf "\"{#DISK_NAME}\":\"${diskarray[$i]}\"}"
        if [ $i -lt $[$length-1] ];then
                printf ','
        fi
done
printf  "\n\t]\n"
printf "}\n"

 

posted @ 2016-05-24 15:50  bass  阅读(196)  评论(0编辑  收藏  举报