From 03499dd17c35b37420dc8764854c9483b62903ad Mon Sep 17 00:00:00 2001 From: mad Date: Tue, 21 Aug 2018 15:18:33 +0200 Subject: [PATCH] checkvm via ssh and local --- nlvmi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nlvmi b/nlvmi index 6c8d9dd..20a4f4f 100755 --- a/nlvmi +++ b/nlvmi @@ -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 {