Do not use tempfile

It is not needed anymore.
This commit is contained in:
Alexis Ben Miloud--Josselin 2018-11-02 17:32:19 +01:00
parent d8c77c59d3
commit 2e516bb734
1 changed files with 3 additions and 10 deletions

View File

@ -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"