checkvm via ssh and local

This commit is contained in:
mad 2018-08-21 15:18:33 +02:00
parent c35b6d927a
commit 03499dd17c
1 changed files with 9 additions and 1 deletions

10
nlvmi
View File

@ -199,7 +199,15 @@ function stopall {
#check if VM is running
function checkvm {
if [ -z $1 ]; then echo "checkvm needs one argument!"; exit 1; fi
ps -ef | grep `cat $RUNDIRECTORY/$1.pid` | grep -v grep >/dev/null && echo "VM is running" || echo "VM is not running"
sqlite3 $SQLITEFILE "SELECT connectstring from vms LEFT JOIN servers ON vms.server = servers.hostname WHERE vmname='$1'" | while read line; do
CONN=$line
if [ ! -z $CONN ]; then
su nlvmi -c "ssh 192.168.0.199 \"RPID=\\\$(<\\\"$RUNDIRECTORY/$1.pid\\\"); ps -ef | grep -v grep | grep \\\$RPID\"" &>/dev/null && echo "VM is running" || echo "VM is not running"
else
ps -ef | grep `cat $RUNDIRECTORY/$1.pid` | grep -v grep >/dev/null && echo "VM is running" || echo "VM is not running"
fi
done
}
function listdir {