-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatchdog.sh
52 lines (39 loc) · 905 Bytes
/
watchdog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# check if $1 exists
if [[ -z $1 ]]
then
echo "Pass a VMID."
exit 1
fi
#------------------------------------------------
# CONSTS
QMLIST="$(qm list | tail -n +2)"
VMID=$1
#------------------------------------------------
# CODE
# check if container exists
if ! echo "$QMLIST" | grep -q " $VMID "
then
printf "\nNo such VM!\n"
exit 1
fi
VMSTATE=$(echo "$QMLIST" | grep " $VMID " | awk '{print $3}')
case $VMSTATE in
"running")
printf "VM %s" "$VMID" "allready running."
echo ""
exit 0
;;
"stopped")
printf "Starting VM %s" "$VMID""."
echo "" # To lazy to fix output spacing
qm start "$VMID"
exit 0
;;
*)
printf "\nUnknown state\n"
exit 1
;;
esac
# If you have gotify or something simmilar you can paste it under "running")
# and under "stopped") for notifications.