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

View file

@ -7,7 +7,7 @@ usage () {
exit 1 exit 1
} }
for DEP in bc tempfile virsh for DEP in bc virsh
do do
if [ -z "$(which $DEP)" ] if [ -z "$(which $DEP)" ]
then then
@ -48,8 +48,6 @@ done
# since libvirt seems to store memoy in KiB, POW must be lowered by 1 # since libvirt seems to store memoy in KiB, POW must be lowered by 1
POW=$((POW / 1024)) POW=$((POW / 1024))
TMPFILE=$(tempfile -s kvmstats)
for VM in $(virsh list --name --all) for VM in $(virsh list --name --all)
do do
CPU=$(virsh vcpucount --maximum --current "$VM") CPU=$(virsh vcpucount --maximum --current "$VM")
@ -60,12 +58,9 @@ do
done | awk '/Physical:/ { size += $2 } END { print int(size / 1024 ^ 3) }') done | awk '/Physical:/ { size += $2 } END { print int(size / 1024 ^ 3) }')
RUN=$(virsh domstate "$VM" | grep -q '^running$' && echo yes || echo no) RUN=$(virsh domstate "$VM" | grep -q '^running$' && echo yes || echo no)
echo "$VM" "$CPU" "$RAM" "$DSK" "$RUN" echo "$VM" "$CPU" "$RAM" "$DSK" "$RUN"
done >"$TMPFILE" done | (
(
echo vm vcpu ram disk running echo vm vcpu ram disk running
cat "$TMPFILE" awk '{ print } /yes$/ { print; vcpu += $2; ram += $3; disk += $4; running++ } END { print "TOTAL(running)", vcpu, ram, disk, running }'
awk '/yes$/ { vcpu += $2; ram += $3; disk += $4; running++ } END { print "TOTAL(running)", vcpu, ram, disk, running }' <"$TMPFILE"
if [ "$SHOW_AVAIL" ] if [ "$SHOW_AVAIL" ]
then then
AV_CPU=$(awk '/^processor/ { cpu++ } END { print cpu }' /proc/cpuinfo) AV_CPU=$(awk '/^processor/ { cpu++ } END { print cpu }' /proc/cpuinfo)
@ -73,5 +68,3 @@ done >"$TMPFILE"
echo AVAILABLE "$AV_CPU" "$AV_MEM" echo AVAILABLE "$AV_CPU" "$AV_MEM"
fi fi
) | column -t ) | column -t
rm "$TMPFILE"