1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#!/bin/sh
set -eu
if test $# -eq 0 ; then
cat <<EOF 1>&2
Usage: $0 <host> [ <mount> ]
List <host>s kvm mounts.
If <mount> is specified, just print that mount's path.
EOF
exit 1
fi
host=$1 ; shift
mount=
if test $# -gt 0; then
mount=$1 ; shift
fi
if test $# -gt 0; then
echo "Unexpected argument: $*" 1>&2
exit 1
fi
sudo virsh dumpxml $host | awk '
/<filesystem type=.mount. / {
source = ""
target = ""
}
/<source dir=/ {
split($2, a, /'\''/)
source = a[2]
}
/<target dir=/ {
split($2, a, /'\''/)
target = a[2]
}
/<\/filesystem>/ {
if ("'$mount'" == "") {
print target, source
} else if ("'$mount'" == target) {
print source
}
}
'
|