capsul-flask/capsulflask/shell_scripts/virsh-list.sh

14 lines
399 B
Bash
Raw Normal View History

#!/bin/sh
printf '['
delimiter=""
virsh list --all | while read -r line; do
if echo "$line" | grep -qE '(running)|(shut off)'; then
capsul_id="$(echo "$line" | awk '{ print $2 }')"
capsul_state="$(echo "$line" | sed -E 's/.*((running)|(shut off))\w*/\1/')"
printf '%s\n {"id":"%s", "state":"%s"}' "$delimiter" "$capsul_id" "$capsul_state"
delimiter=","
fi
done
printf '\n]\n'