diff --git a/watchdog.sh b/watchdog.sh index 374853e..2e2a2b3 100644 --- a/watchdog.sh +++ b/watchdog.sh @@ -10,32 +10,34 @@ fi #------------------------------------------------ # CONSTS -QMLIST="$(qm list | tail -n +2)" -VMID=$1 +VMID="$1" +QMSTAT="$(/usr/sbin/qm status $VMID )" > /dev/nul> /dev/null0 #------------------------------------------------ # CODE # check if container exists -if ! echo "$QMLIST" | grep -q " $VMID " +if echo $QMSTAT | grep "not exist" then printf "\nNo such VM!\n" exit 1 fi -VMSTATE=$(echo "$QMLIST" | grep " $VMID " | awk '{print $3}') + +VMSTATE=$(echo "$QMSTAT" | awk '{print $2}') +#echo $VMSTATE case $VMSTATE in "running") - printf "VM %s" "$VMID" "allready running." - echo "" + #printf "VM %s" "$VMID" "allready running." + #echo "" exit 0 ;; "stopped") - printf "Starting VM %s" "$VMID""." - echo "" # To lazy to fix output spacing + printf "\nStarting VM %s" "$VMID\n" + #echo "" # To lazy to fix output spacing qm start "$VMID" exit 0 @@ -49,4 +51,4 @@ case $VMSTATE in esac # If you have gotify or something simmilar you can paste it under "running") -# and under "stopped") for notifications. \ No newline at end of file +# and under "stopped") for notifications.