From 2e516bb734cb0c3276858cec6a9c56a8a16d00ae Mon Sep 17 00:00:00 2001 From: Alexis Ben Miloud--Josselin Date: Fri, 2 Nov 2018 17:32:19 +0100 Subject: [PATCH] Do not use tempfile It is not needed anymore. --- kvmstats | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/kvmstats b/kvmstats index b14586b..6d91bff 100755 --- a/kvmstats +++ b/kvmstats @@ -7,7 +7,7 @@ usage () { exit 1 } -for DEP in bc tempfile virsh +for DEP in bc virsh do if [ -z "$(which $DEP)" ] then @@ -48,8 +48,6 @@ done # since libvirt seems to store memoy in KiB, POW must be lowered by 1 POW=$((POW / 1024)) -TMPFILE=$(tempfile -s kvmstats) - for VM in $(virsh list --name --all) do CPU=$(virsh vcpucount --maximum --current "$VM") @@ -60,12 +58,9 @@ do done | awk '/Physical:/ { size += $2 } END { print int(size / 1024 ^ 3) }') RUN=$(virsh domstate "$VM" | grep -q '^running$' && echo yes || echo no) echo "$VM" "$CPU" "$RAM" "$DSK" "$RUN" -done >"$TMPFILE" - -( +done | ( echo vm vcpu ram disk running - cat "$TMPFILE" - awk '/yes$/ { vcpu += $2; ram += $3; disk += $4; running++ } END { print "TOTAL(running)", vcpu, ram, disk, running }' <"$TMPFILE" + awk '{ print } /yes$/ { print; vcpu += $2; ram += $3; disk += $4; running++ } END { print "TOTAL(running)", vcpu, ram, disk, running }' if [ "$SHOW_AVAIL" ] then AV_CPU=$(awk '/^processor/ { cpu++ } END { print cpu }' /proc/cpuinfo) @@ -73,5 +68,3 @@ done >"$TMPFILE" echo AVAILABLE "$AV_CPU" "$AV_MEM" fi ) | column -t - -rm "$TMPFILE"