Hi Guys,
We have developed a .sh script in the past, which worked great on ESX 3.X.
The script basically registers all virtual machines found across all vmfs volumes on our ESX servers as well as powering on the critical ones, such as Active Directory and alike.
(A copy of the script is below)
We attempted to re-run this script on our ESX 4.0 environment, and the script doesn't work.
What modifications do we need to make for this to work on ESX 4.0?
<----
SCRIPT EXTRACT START -
>
echo "++ REGISTER> All Virtual Machines..."
for i in `find /vmfs/volumes/ -name "*.vmx" `
do
echo "Registering VM $i"
vmware-cmd -s register $i
done
read -p ' *** Finished Importing '
echo '+++ START> Active Directory Domain Controllers'
for i in `find /vmfs/volumes/ -name "servername*.vmx" `
do
echo "Starting VM $i"
vmware-cmd $i start hard
done
read -p '*** Ensure Active Directory has started.. press <RETURN> to continue.'
echo '+++ START> VMWare VirtualCenter (dependant on server-SQL)'
for i in `find /vmfs/volumes/ -name "vcenter_servername*.vmx" `
do
echo "Starting VM $i"
vmware-cmd $i start hard
done
echo '+++ START> Core File Server'
for i in `find /vmfs/volumes/ -name "core_fileservername*.vmx" `
do
echo "Starting VM $i"
vmware-cmd $i start hard
done
<----
SCRIPT EXTRACT END -
>
Feedback is much appreciated & points rewarded..
Thanks
R.
Try to run the script in debug mode to see at which line it stops.
sh -x script_name
Andre
Have You given full listing?
In script hardcoded vm names are "servername.vmx", "vcenter_servername.vmx", "core_fileservername*.vmx", names of vmx files remained the same?
After adding in the beginning
#!/bin/bash
and make a shell script executable by the user/owner
chmod u+x script.sh
it worked on ESX4.
Not sure what you mean by Have you given full listing?
In actual fact, we use server*.vmx to find all the vmx files across our /vms/volumes...
I only used servername to hide the actual name of our servers..
so it should look like this with your suggestion.. and this works???
#!/bin/bash
for i in `find /vmfs/volumes/ -name "*.vmx" `
do
echo "Registering VM $i"
vmware-cmd -s register $i
done
read -p ' *** Finished Importing '
echo '+++ START> Active Directory Domain Controllers'
for i in `find /vmfs/volumes/ -name "svr00*.vmx" `
do
echo "Starting VM $i"
vmware-cmd $i start hard
done
read -p '*** Ensure Active Directory has started.. press <RETURN> to continue.'
echo '+++ START> VMWare VirtualCenter (dependant on svrsql002-SQL)'
for i in `find /vmfs/volumes/ -name "vcenterserver*.vmx" `
do
echo "Starting VM $i"
vmware-cmd $i start hard
done
echo '+++ START>File Server'
for i in `find /vmfs/volumes/ -name "fileshareserver*.vmx" `
do
echo "Starting VM $i"
vmware-cmd $i start hard
done
Will run the chmod u+x on the script when we next run the import...
Difficult to run the test again right now.. might look through the logs to see what happened last time? vmware.log, etc?
You can try to check hosts.log
Andre
By posting of the full listing of the script I meant the whole source code of the script and not just its working part.
Yes, the script will work if in the beginning of the script the shell
#!/bin/bash
is specified and file of script has the required rights
chmod u+x <yourscriptfilename>
.
At least, this script worked in my environment (ESX4), found all vmx files and powered on the found vm after editing the "servername.vmx" name for my environment.
You can check workability of your script if you change commands "vmware-cmd ..." => "echo vmware-cmd ....", then the script will just write on the console what it is going to do and will not register and power on the vms.
Yes, I have posted the whole script, from start to finish.
But just incase, I have attached it to this post.
I have replaced the actual server names with 'sample' names.
Let me know what you think.
I'll test it out with the comments ammended as you have suggested.
Thanks for your help
R.
The string
#!/bin/bash
should be the first line of the shell script.
In the attachment you can find 2 versions of your script :
importvms2010_tst.sh - test version (does nothing, just outputs to the console)
importvms2010_wrk.sh - work version, but you will have to replace "servername" "servername2" "servername3" with real names of your vms.
If the test version outputs:
++ REGISTER> All Virtual Machines... Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-01/vm-01.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-01/vm-01.vmx Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-02a/vm-02a.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-02a/vm-02a.vmx Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-14/vm-14.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-14/vm-14.vmx Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-15/vm-15.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-15/vm-15.vmx Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-02/vm-02.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-02/vm-02.vmx Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-04/vm-04.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-04/vm-04.vmx Registering VM /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-03/vm-03.vmx vmware-cmd -s register /vmfs/volumes/4bd55e53-3b30a016-7320-001517c52878/vm-03/vm-03.vmx *** Finished Importing +++ START> Active Directory Domain Controllers *** Ensure Active Directory has started.. press <RETURN> to continue. +++ START> VMWare VirtualCenter (dependant on server-SQL) +++ START> Core File Server
then everything is ok.
If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Thanks for updating the scripts.. I'll check it out and let you know..
Should the script not work on the day of test..(and I know there are two scripts here, but just as a backup)..
What are the commands to run on the ESX host to find all VMX files across all datastores and place it into a text file.
And then register all vmx files found in that txt file in vcenter?
Just incase something fails with the script, I'd like to have the commands available on hand manually.
That way, we can quickly search for all vms files on the datastores, register them and then power them on in the order required.
Thanks
Apparently you are doing something wrong. Have you loaded my version of your script?
How do you upload the script on the ESX host? How do you set file permissions of the script? How do you run the script?
Could you describe the details?
The commands to run on the ESX host to find all VMX files
In your script it is
find /vmfs/volumes/ -name "*.vmx"
Register all vmx files found in vcenter
In your script it is a block
for i in `find /vmfs/volumes/ -name "*.vmx" ` do echo "Registering VM $i" vmware-cmd -s register $i done