#!/bin/sh # Stops domains given as arguments opts=$(getopt -o 'as' -l 'all,save' -- "$@") eval set -- "$opts" all=0 save=0 while true do case $1 in '-a'|'--all') all=1; shift; continue ;; '-s'|'--save') save=1; shift; continue ;; '--') shift; break;; esac done [ $all -eq 1 ] && domains="$(virsh list | grep running | awk '{print $2}')" || domains="$@" for domain in $domains do [ $save -eq 1 ] && virsh managedsave $domain || virsh shutdown $domain done