From ccd9c069f44bd59b8d7cfe95427a138b593d1dcd Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Sat, 25 Mar 2023 00:00:06 +0100 Subject: [PATCH] add remote-shutdown script --- remote-shutdown | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 remote-shutdown diff --git a/remote-shutdown b/remote-shutdown new file mode 100755 index 0000000..37cfd03 --- /dev/null +++ b/remote-shutdown @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +sessions=$(w | sed '1,2d' | wc -l) + +if [ $sessions -gt 0 ] ; then + echo Users still logged in! Not continuing + exit 1 +fi + +# virsh inserts an additional newline, so this is the number of +# running VMs + 1 +running_vms=$(virsh -c qemu:///system list --state-running --uuid | wc -l) + +if [ $running_vms -gt 1 ] ; then + echo VMs still running! Not continuing + exit 1 +fi + +poweroff