Shell Skript: Remove Virtual Machine
Das folgende Shell Skript dient zum Löschen einer virtuellen Maschine. Als Virtualisierungslösung wird VMware Server 2.0.x vorausgesetzt.
Erstellen Sie durch den folgenden Befehl das Skript im Verzeichnis ~/sh.
[root@centos5 ~]# vi ~/sh/vmware_remove.sh
Fügen Sie jetzt das folgende Skript in die Datei vmware_remove.sh ein.
Hinweis: Dieses Skript ist für CentOS 5.x und CentOS 6.x ausgelegt.
###########################################################################
## ##
## Remove Virtual Machine ##
## ##
## Creation: 19.04.2010 ##
## Last Update: 20.10.2013 ##
## ##
## Copyright (c) 2010-2013 by Georg Kainzbauer <http://www.gtkdb.de> ##
## ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
###########################################################################
#!/bin/bash
# Name of the virtual machine
VM=$1
# Directory with your virtual machines
VMDIR=/data/vmware
# Password for the VMware server
PASSWORD=$2
###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################
if [ -z ${VM} ] ; then
echo "Please specify virtual machine."
exit 1
fi
if [ -z ${PASSWORD} ] ; then
echo "Please specify the password for the VMware server."
exit 1
fi
if [ -d ${VMDIR}/${VM} ] ; then
if $(vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} list | grep "${VM}/${VM}.vmx$" >/dev/null) ; then
echo "Stopping virtual machine ..."
vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} stop "[standard] ${VM}/${VM}.vmx"
fi
if $(vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} listRegisteredVM | grep "${VM}/${VM}.vmx$" >/dev/null) ; then
echo "Unregistering virtual machine ..."
vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} unregister "[standard] ${VM}/${VM}.vmx"
fi
echo "Removing virtual machine ..."
rm -rf ${VMDIR}/${VM}
else
echo "Virtual machine does not exist."
fi
exit 0
## ##
## Remove Virtual Machine ##
## ##
## Creation: 19.04.2010 ##
## Last Update: 20.10.2013 ##
## ##
## Copyright (c) 2010-2013 by Georg Kainzbauer <http://www.gtkdb.de> ##
## ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
###########################################################################
#!/bin/bash
# Name of the virtual machine
VM=$1
# Directory with your virtual machines
VMDIR=/data/vmware
# Password for the VMware server
PASSWORD=$2
###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################
if [ -z ${VM} ] ; then
echo "Please specify virtual machine."
exit 1
fi
if [ -z ${PASSWORD} ] ; then
echo "Please specify the password for the VMware server."
exit 1
fi
if [ -d ${VMDIR}/${VM} ] ; then
if $(vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} list | grep "${VM}/${VM}.vmx$" >/dev/null) ; then
echo "Stopping virtual machine ..."
vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} stop "[standard] ${VM}/${VM}.vmx"
fi
if $(vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} listRegisteredVM | grep "${VM}/${VM}.vmx$" >/dev/null) ; then
echo "Unregistering virtual machine ..."
vmrun -T server -h https://localhost:8333/sdk -u root -p ${PASSWORD} unregister "[standard] ${VM}/${VM}.vmx"
fi
echo "Removing virtual machine ..."
rm -rf ${VMDIR}/${VM}
else
echo "Virtual machine does not exist."
fi
exit 0
Ändern Sie anschließend die Zugriffsrechte der Datei.
[root@centos5 ~]# chmod 0700 ~/sh/vmware_remove.sh
Beim Aufruf des Skripts müssen Sie den Namen der virtuellen Maschine und das Passwort für den VMware Server angeben.
[root@centos5 ~]# ~/sh/vmware_remove.sh <VMNAME> <PASSWORD>
Dieser Eintrag wurde am 12.06.2011 erstellt und zuletzt am 05.04.2015 bearbeitet.
Direkter Link zu dieser Seite: http://www.gtkdb.de/index_33_1308.html
[ Zur Startseite ] [ Zur Kategorie ]
© 2004-2021 by Georg Kainzbauer