Update file watchdog.sh

This commit is contained in:
Yuru 2025-02-25 16:14:14 +00:00
parent e5f10f0374
commit 7bdb746d19

View File

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