mirror of
https://github.com/sixdimensionalarray/esxidown.git
synced 2026-04-25 07:15:53 +03:00
[GH-ISSUE #3] Get the VM IDs using vim-cmd vmsvc/getallvms question #1
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/esxidown#1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ddd2015 on GitHub (May 22, 2015).
Original GitHub issue: https://github.com/sixdimensionalarray/esxidown/issues/3
The readme states:
Get the VM IDs using vim-cmd vmsvc/getallvms and customize the esxidown.sh script.
The code states:
these are the VM IDs to shutdown in the order specified
use the SSH shell, run "vim-cmd vmsvc/getallvms" to get ID numbers
specify IDs separated by a space
SERVERIDS=$(vim-cmd vmsvc/getallvms | sed -e '1d' -e 's/ [.*$//' | awk '$1 ~ /^[0-9]+$/ {print $1}')
I ran vim-cmd vmsvc/getallvms and my VM IDs are 2 3 4
Were do I place my 2 3 4 IDs?
This might be really obvious, but I cant see it?
Thanks
@sixdimensionalarray commented on GitHub (May 22, 2015):
The readme is a little bit outdated - you don't need to run the vim-cmd manually anymore. I will fix that.
You don't need to change anything for the script to work. The script was modified so that it automatically runs vim-cmd to get all the VM IDs using the command inside the dollar sign/parenthesis, so all VMs get shut down by default automatically.
If you want to shutdown VMs explicitly by number (such as 2 3 4), rather than the script figuring it out for you, then you can modify the SERVERIDS line like so:
...and then the script will only shut down those VMs. But you probably just want to leave it alone and let it do the default behavior where it runs the command and fills those IDS in for you.
@ddd2015 commented on GitHub (May 23, 2015):
Thanks for the info!
I ran the script and nothing happened, which is why I was looking at the above line.
Here is my info...
Esxi 5.5 free version
I copied both files to the root of our datastore.
From a Windows 7 VM, I ran used WinSCP to copy the files to our datastore.
In WinSCP, I did a properties on both files and added execute rights
In a Windows 7 command prompt I ran:
c:\util\putty\putty\plink.exe esxi -l root -pw rootspassword "sh /vmfs/volumes/datastorename/async.sh /vmfs/volumes/datastorename/esxidown.sh"
I get no errors, but nothing shuts down?
I vsphere client, I watched the events tab, I see a login and logout, but nothing happens?
Can you offer any troubleshooting tips?
Thanks
@sixdimensionalarray commented on GitHub (May 23, 2015):
Try changing those lines like this:
and then running the script again. Does it work after that?
If it still doesn't work after that, I'm not sure and will have to try testing the script as it is on an ESXi 5.5 server. It's possible something changed and the script no longer works, might need some debugging.
@sixdimensionalarray commented on GitHub (May 23, 2015):
Also, if you log in to your ESXi server using SSH, you can manually run the command and see what it prints out on the screen using the following (to see if there are any errors):
./vmfs/volumes/datastorename/esxidown.sh
@ddd2015 commented on GitHub (May 23, 2015):
I will test and follow back up, it may not be until after memorial day though. Thanks
@ddd2015 commented on GitHub (May 26, 2015):
Hi, I just got back to working on this now.
I first opened Putty and ssh in.
I issued
./vmfs/volumes/datastorename/esxidown.sh
but got:
-sh: ./vmfs/volumes/datastorename/esxidown.sh: not found
(I did replace "datastorename" with our datastore name)
I then did a:
~ # cd /vmfs/volumes/datastorename
and then issued a ls and do see esxidown,sh
Can you offer any suggestions on why I get "not found" when I manually run esxidown.sh?
Thanks
@ddd2015 commented on GitHub (May 26, 2015):
I have some info to add...
I first thought it might have something to do with trying to run files from the root of the datastore, so I created a subfolder name utils and copied both files there with WinSCP.
In WinSCP, I did a properties on both files and added execute rights.
I then ssh in with Putty and run:
./vmfs/volumes/datastorename/utils/esxidown.sh
Same error:
-sh: ./vmfs/volumes/datastorename/utils/esxidown.sh: not found
Next I...
cd vmfs/volumes/datastorename/utils
Issue a ls and see esxidown.sh
Then, at the prompt:
/vmfs/volumes/datastorename/utils #
I issued esxidown.sh
I got:
-sh: esxidown.sh: not found
I then issued ./esxidown.sh
-sh: ./esxidown.sh: not found
./esxidown.sh: line 8:
./esxidown.sh: line 12:
./esxidown.sh: line 16:
./esxidown.sh: line 19:
./esxidown.sh: line 21:
./esxidown.sh: line 23: {
./esxidown.sh: line 24: redir error
Insufficient arguments.
./esxidown.sh: line 26:
./esxidown.sh: line 53: syntax error: unexpected word (expecting "do")
Can you review the above line errors?
Thanks
@ddd2015 commented on GitHub (May 26, 2015):
And another update...
Last Friday when I first looked at esxidown.sh, I reviewed the upper variable section and changed the below two variables:
WAIT_TRYS=20
I changed to:
WAIT_TRYS=1
WAIT_TIME=10
I changed to:
WAIT_TIME=120
My ultimate goal was, make one guest vm shutdown call, wait two minutes, then check that guest vm.
If that guest vm is still on, then issue a guest hard shutdown and go on to next guest.
If that guest vm was off, then go on to next guest vm.
See todays errors, I put the esxidown.sh file back to original.
I then ran a second test...
This time it work again with no errors!
/vmfs/volumes/datastorename/utils# sh ./esxidown.sh
Entering maintenance mode...
Attempting shutdown of guest VM ID 3...
Waiting for guest VM ID 3 to shutdown (attempt #1)...
Attempting shutdown of guest VM ID 4...
Waiting for guest VM ID 4 to shutdown (attempt #1)...
Attempting shutdown of guest VM ID 5...
Waiting for guest VM ID 5 to shutdown (attempt #1)...
Guest VM shutdown complete...
Shutting down ESXi host after 10 seconds...
Exiting maintenance mode...
/vmfs/volumes/datastorename/utils #
I will next work on trying to get the above to run through plink and follow back up.
But, in the meantime, how can I achieve the below goal...
Thanks
@ddd2015 commented on GitHub (May 26, 2015):
I just successfully ran:
c:\util\putty\putty\plink.exe esxi -l root -pw rootspassword "sh /vmfs/volumes/datastorename/utils/async.sh /vmfs/volumes/datastorename/esxidown.sh"
So my first issue appears to be that I could not run files from the root of my datastore, after creating a subfolder named utils and placing the two files there, the script worked!
The last thing I would like to do is properly set the WAIT_TRYS and WAIT_TIME, can you offer assistance in correctly setting these values to obtain my above mentioned goal?
Thanks
@sixdimensionalarray commented on GitHub (May 26, 2015):
That's great! Glad you figured it out!
A few comments:
Regarding your requested goal, I think you can change the settings like so to get the exact behavior you are asking for:
This means, it will try to shut down 1 time, then wait 120 seconds, then verify it is down or just turn it off. After it turns it off though, it usually sleeps for WAIT_TIME to let the machine shut down. In your case, you might shorten the timeout on that line a bit (so it doesn't do a poweroff and then wait 120 seconds, or just comment that line out):
The net result of these changes (as shown above) should give you:
@sixdimensionalarray commented on GitHub (May 27, 2015):
Just a personal note, I prefer a lower wait time and more tries myself - I have found that works better because the script checks more frequently for the shutdown event, but can still check for a long time.
For example... with the default, it will check 20 times, and wait 10 seconds each time to verify shutdown.
20 * 10 = 200 seconds of total time waiting if it has to run all 20 times.
So an alternative for you would be to instead wait 10 times for 12 seconds each (10 * 12 = 120 seconds as well):
@ddd2015 commented on GitHub (May 27, 2015):
Thank you very much!
As you can probably tell, I am learning on the fly...
I really appreciate your comments on having lower wait times and more try times to allow for more script checks on the shutdown event, that now makes much more sense to me.
Thank you again for all of your help...
And another plus is, we verified your esxidown script does work with esxi 5.5
Thanks
@sixdimensionalarray commented on GitHub (May 27, 2015):
You're welcome, and no worries - glad to help.
I'll update the readme to reflect that the script works with ESXi 5.5.
Thanks for trying out the script, and please feel free to contribute if you have any suggestions for improvements.
All the best!
@ddd2015 commented on GitHub (May 27, 2015):
Hi, I have one more question, regarding logging the output of the script.
When I ran esxidown manually I saw output in the putty console...
/vmfs/volumes/datastorename/utils# sh ./esxidown.sh
Entering maintenance mode...
Attempting shutdown of guest VM ID 3...
Waiting for guest VM ID 3 to shutdown (attempt #1)...
Attempting shutdown of guest VM ID 4...
Waiting for guest VM ID 4 to shutdown (attempt #1)...
Attempting shutdown of guest VM ID 5...
Waiting for guest VM ID 5 to shutdown (attempt #1)...
Guest VM shutdown complete...
Shutting down ESXi host after 10 seconds...
Exiting maintenance mode...
/vmfs/volumes/datastorename/utils #
When I run a Windows 7 batch file with the line:
c:\util\putty\putty\plink.exe esxi -l root -pw rootspassword "sh /vmfs/volumes/datastorename/utils/async.sh /vmfs/volumes/datastorename/esxidown.sh" >> c:\log.txt
I dont get the above output in the log.txt file?
Can you offer any suggestions?
Thanks
@sixdimensionalarray commented on GitHub (May 28, 2015):
The way the script is designed, it is very hard to get output back as a result on your local machine because you fire off the script and then disconnect immediately.
The reason for this is because the async.sh command runs the script asynchronously so you can connect, run the command using SSH and disconnect immediately. You want that behavior to a certain extent, because you don't want to have the script running interactively, synchronously, in case the power or network connection goes out and suddenly interrupts the script, preventing it from finishing and preventing all the VMs or the ESXi host from shutting down.
If you want to preserve the log on the datastore at least, so you can check the output later, you could change the async.sh script to be something like this:
Change this line:
To this line:
If you aren't worried about your SSH session being disconnected right in the middle of the script running (which I would be worried about), you can also just run the script synchronously and you should get your output: