From 80ba982841ed8f61278156cffe37460659a08066 Mon Sep 17 00:00:00 2001 From: Alexis Ben Miloud--Josselin Date: Fri, 8 Jun 2018 11:25:42 +0200 Subject: [PATCH] Run lvs only one time Also make the case esac readable --- kvmstats.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kvmstats.sh b/kvmstats.sh index bf8d06c..705003d 100644 --- a/kvmstats.sh +++ b/kvmstats.sh @@ -40,6 +40,9 @@ do done TMPFILE=$(tempfile) +LVSOUT=$(tempfile) + +lvs --units b --nosuffix >$LVSOUT for VM in $(virsh list --all --name) do @@ -48,9 +51,14 @@ do for DEV in $(hxselect -s'\n' 'domain devices disk[device=disk] source' $TMPFILE awk '{ vcpu += $2; ram += $3; disk += $4 } END { print "TOTAL", vcpu, ram, disk }' <$TMPFILE ) | column -t -rm $TMPFILE +rm $TMPFILE $LVSOUT