[GH-ISSUE #3] Get the VM IDs using vim-cmd vmsvc/getallvms question #1

Closed
opened 2026-02-27 23:03:16 +03:00 by kerem · 15 comments
Owner

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

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
kerem closed this issue 2026-02-27 23:03:16 +03:00
Author
Owner

@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:

SERVERIDS=2 3 4

...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.

<!-- gh-comment-id:104803037 --> @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: ``` SERVERIDS=2 3 4 ``` ...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.
Author
Owner

@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

<!-- gh-comment-id:104805330 --> @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
Author
Owner

@sixdimensionalarray commented on GitHub (May 23, 2015):

Try changing those lines like this:

# 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}')
SERVERIDS=2 3 4

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.

<!-- gh-comment-id:104807925 --> @sixdimensionalarray commented on GitHub (May 23, 2015): Try changing those lines like this: ``` # 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}') SERVERIDS=2 3 4 ``` 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.
Author
Owner

@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

<!-- gh-comment-id:104808053 --> @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
Author
Owner

@ddd2015 commented on GitHub (May 23, 2015):

I will test and follow back up, it may not be until after memorial day though. Thanks

<!-- gh-comment-id:104809336 --> @ddd2015 commented on GitHub (May 23, 2015): I will test and follow back up, it may not be until after memorial day though. Thanks
Author
Owner

@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

<!-- gh-comment-id:105655675 --> @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
Author
Owner

@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

I then issued sh ./esxidown.sh
That worked, sort of...
I got alot of errors....
./esxidown.sh: line 3:
not found
./esxidown.sh: line 8:
not found
./esxidown.sh: line 12:
not found
./esxidown.sh: line 16:
not found
./esxidown.sh: line 19:
not found
./esxidown.sh: line 21:
not found
./esxidown.sh: line 23: {
not found
./esxidown.sh: line 24: redir error
Insufficient arguments.
./esxidown.sh: line 26:
not found
./esxidown.sh: line 53: syntax error: unexpected word (expecting "do")

Can you review the above line errors?

Thanks

<!-- gh-comment-id:105679608 --> @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 I then issued sh ./esxidown.sh That worked, sort of... I got alot of errors.... ./esxidown.sh: line 3: : not found ./esxidown.sh: line 8: : not found ./esxidown.sh: line 12: : not found ./esxidown.sh: line 16: : not found ./esxidown.sh: line 19: : not found ./esxidown.sh: line 21: : not found ./esxidown.sh: line 23: { : not found ./esxidown.sh: line 24: redir error Insufficient arguments. ./esxidown.sh: line 26: : not found ./esxidown.sh: line 53: syntax error: unexpected word (expecting "do") Can you review the above line errors? Thanks
Author
Owner

@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...

  • one call to shutdown guest vm
  • wait for 2 minutes
  • check that guest vm
  • if that guest vm is still on, issue a hard shutdwon of that guest vm and move on to next vm.
  • if that guest vm is off, them move on to next guest vm.

Thanks

<!-- gh-comment-id:105690394 --> @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... - one call to shutdown guest vm - wait for 2 minutes - check that guest vm - if that guest vm is still on, issue a hard shutdwon of that guest vm and move on to next vm. - if that guest vm is off, them move on to next guest vm. Thanks
Author
Owner

@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

<!-- gh-comment-id:105693613 --> @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
Author
Owner

@sixdimensionalarray commented on GitHub (May 26, 2015):

That's great! Glad you figured it out!

A few comments:

  • when running shell scripts in Unix, if you are within the folder of the shell script, you run the command with a dot before the slash. So if cd into the directory "/vmfs/volumes/datastorename/utils/" then to run the script, you write the command like "./esxidown.sh". If you run the script directly in the subfolder, then you just run it without the dot, for example "/vmfs/volumes/datastorename/utils/esxidown.sh". I think you already figured this out.
  • it's possible that somehow your line endings may have gotten screwed up in the file originally (probably when you edited the file). Windows line endings can cause problems on Unix and vice versa. What I would suggest if that happens is to use the Linux utility "dos2unix" on the file, if you can (or use a tool like Notepad++ in Windows to convert to Unix line endings) and then try running the script again. It looks like replacing the file with the original one fixed that issue for you.

Regarding your requested goal, I think you can change the settings like so to get the exact behavior you are asking for:

# script waits WAIT_TRYS times, WAIT_TIME seconds each time
# number of times to wait for a VM to shutdown cleanly before forcing power off.
WAIT_TRYS=1

# how long to wait in seconds each time for a VM to shutdown.
WAIT_TIME=120

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):

        else
            # force power off and wait a little (you could use vmsvc/power.suspend here instead)
            echo "Unable to gracefully shutdown guest VM ID $SRVID... forcing power off."
            if [ $TEST -eq 0 ]; then
                vim-cmd vmsvc/power.off $SRVID
            fi
           # change line #40 from: 
           #sleep $WAIT_TIME
           #to:
           sleep 10
        fi

The net result of these changes (as shown above) should give you:

  • one call to shutdown the VM
  • wait 2 minutes for it to shutdown
  • if it doesn't shut down, it will be forcefully powered off and then script sleeps for 10 seconds (the change to line #40)
  • the script moves on to the next VM and repeats the process.
<!-- gh-comment-id:105700516 --> @sixdimensionalarray commented on GitHub (May 26, 2015): That's great! Glad you figured it out! A few comments: - when running shell scripts in Unix, if you are within the folder of the shell script, you run the command with a dot before the slash. So if cd into the directory "/vmfs/volumes/datastorename/utils/" then to run the script, you write the command like "./esxidown.sh". If you run the script directly in the subfolder, then you just run it without the dot, for example "/vmfs/volumes/datastorename/utils/esxidown.sh". I think you already figured this out. - it's possible that somehow your line endings may have gotten screwed up in the file originally (probably when you edited the file). Windows line endings can cause problems on Unix and vice versa. What I would suggest if that happens is to use the Linux utility "dos2unix" on the file, if you can (or use a tool like Notepad++ in Windows to convert to Unix line endings) and then try running the script again. It looks like replacing the file with the original one fixed that issue for you. Regarding your requested goal, I think you can change the settings like so to get the exact behavior you are asking for: ``` # script waits WAIT_TRYS times, WAIT_TIME seconds each time # number of times to wait for a VM to shutdown cleanly before forcing power off. WAIT_TRYS=1 # how long to wait in seconds each time for a VM to shutdown. WAIT_TIME=120 ``` 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): ``` else # force power off and wait a little (you could use vmsvc/power.suspend here instead) echo "Unable to gracefully shutdown guest VM ID $SRVID... forcing power off." if [ $TEST -eq 0 ]; then vim-cmd vmsvc/power.off $SRVID fi # change line #40 from: #sleep $WAIT_TIME #to: sleep 10 fi ``` The net result of these changes (as shown above) should give you: - one call to shutdown the VM - wait 2 minutes for it to shutdown - if it doesn't shut down, it will be forcefully powered off and then script sleeps for 10 seconds (the change to line #40) - the script moves on to the next VM and repeats the process.
Author
Owner

@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):

# script waits WAIT_TRYS times, WAIT_TIME seconds each time
# number of times to wait for a VM to shutdown cleanly before forcing power off.
WAIT_TRYS=10

# how long to wait in seconds each time for a VM to shutdown.
WAIT_TIME=12
<!-- gh-comment-id:105701010 --> @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): ``` # script waits WAIT_TRYS times, WAIT_TIME seconds each time # number of times to wait for a VM to shutdown cleanly before forcing power off. WAIT_TRYS=10 # how long to wait in seconds each time for a VM to shutdown. WAIT_TIME=12 ```
Author
Owner

@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

<!-- gh-comment-id:105702720 --> @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
Author
Owner

@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!

<!-- gh-comment-id:105703647 --> @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!
Author
Owner

@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

<!-- gh-comment-id:106095877 --> @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
Author
Owner

@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:

nohup sh $1 > /dev/null 2>&1 &

To this line:

nohup sh $1 >> /vmfs/volumes/datastorename/utils/esxidown.log 2>&1 &

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:

c:\util\putty\putty\plink.exe esxi -l root -pw rootspassword "sh /vmfs/volumes/datastorename/esxidown.sh" >> c:\log.txt
<!-- gh-comment-id:106121653 --> @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: ``` nohup sh $1 > /dev/null 2>&1 & ``` To this line: ``` nohup sh $1 >> /vmfs/volumes/datastorename/utils/esxidown.log 2>&1 & ``` 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: ``` c:\util\putty\putty\plink.exe esxi -l root -pw rootspassword "sh /vmfs/volumes/datastorename/esxidown.sh" >> c:\log.txt ```
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/esxidown#1
No description provided.