Files
scripts/Linux Control Virtual Machine/restart-vm.sh
2024-10-14 00:08:40 +02:00

27 lines
692 B
Bash

#!/bin/bash
# alle VMs
VMS="debian2 omv3"
for VM in `echo $VMS`
do
# status VM
STATUS=`echo "select status from devices where hostname='$VM'" | mysql -u observium -pobservium -D observium -h 192.168.100.8 -s`
# alten status lesen
STATUS_ALT=`cat STATUS_$VM`
# wenn alter status = 0 und aktueller auch 0 -> poweroff VM
if [ "$STATUS_ALT" == "0" ]; then
if [ "$STATUS" == "0" ]; then
echo "power down $VM"
/home/andre/CVM.sh stop $VM
sleep 10
echo "power up $VM"
/home/andre/CVM.sh start $VM
fi
fi
# aktueller status nach alten status schreiben
echo "$STATUS" > STATUS_$VM
done