天天看點

shell

#!/bin/bash

ls /vm/vm/ | grep -o -P '[Ss]\d{6}' > /tmp/vmlist

ps aux >|/tmp/pslist

while read line

do

   du -sh /vm/vm/$line/data.img | awk '{print $1}' >/tmp/disktmp

   grep $line /tmp/pslist | awk '{if ( $11 == "/usr/bin/kvm" && $12 =="-name") printf "%s\t%s\t%s\t%s\t%s\t[zbz]\n",$13,$3,$4,$5,$6}' >/tmp/disktmp1

   if [ `ls -l /tmp/disktmp1 | awk '{print $5}'` -eq 0 ];then

       echo "$line 0 0 0 0"| awk '{printf "%s\t%s\t%s\t%s\t%s\t[zbz]\n",$1,$2,$3,$4,$5}' >|/tmp/disktmp1

       paste  /tmp/disktmp1 /tmp/disktmp >/tmp/disklist

   else

   fi

   cat /tmp/disklist |awk -v OFS='\t' '{printf "%s\\t%s\\t%s\\t%s\\t%s\\t%s%s\n",$1,$2,$3,$7,$5,$4,$6}'

done < /tmp/vmlist

rm -f /tmp/disktmp1 /tmp/disktmp /tmp/disklist /tmp/pslist /tmp/vmlist

本文轉自 freeterman 51CTO部落格,原文連結:http://blog.51cto.com/myunix/1340260,如需轉載請自行聯系原作者