110-vm-exists
#!/bin/bash
#
# Check if VM exists
#
if [ "$UID" -eq 0 ]
  then echo "This script should NOT be run as root."
  exit 1
fi
#
# Source config file
if [ ! -f ~/.vbconfig ]; then
    echo "Config File ~/.vbconfig not found!"
    echo "Run: set-folders to create .vbconfig"
    exit 1
fi
. ~/.vbconfig
#
VB_VM_NAME=$1
if [[ $VB_VM_NAME = "" ]]; then
  echo "2"
  exit
fi
#
VM_EXISTS=`VBoxManage list vms|grep -c '^"'${VB_VM_NAME}'"'`
if [ $VM_EXISTS -eq 0 ]; then
  echo "0"
else
  echo "1"
fi
#
exit

QR Code
QR Code scripts:110-vm-exists (generated for current page)