VMware Cloud Community
Sureshadmin
Contributor
Contributor

Need a powershell script to trigger a shell script in ESX server

Hi,

I have a shell script located in /tmp/admin.sh in all of my ESX servers.

I need a powershell script to log into each of my ESX server and trigger the script. It should pass this command ./admin.sh

All ESX servers names will be stored in a TXT file which powershell script should take as a input.

Thanks in Advance.

0 Kudos
4 Replies
admin
Immortal
Immortal

There is no way to do this by API. Also you should be aware that whatever you do in this manner will not be compatible with ESXi. The only option you have is to use SSH and I can't really recommend that.

=====

Carter Shanklin

Read the PowerCLI Blog
[Follow me on Twitter|http://twitter.com/cshanklin]

0 Kudos
Texiwill
Leadership
Leadership

Hello,

It is possible to do this, you need to either use the PuTTY plink.exe to make it happen or some other tool to get to the ESX host and ensure you do not try this if your host is ESXi, which is pretty easy to determine in powershell.

The problem is that you need to also log any command run so you most likely need to run the command using 'sudo' which itself is an issue.

Also never place a script in /tmp as that directory gets emptied over time.

Carter does not recommend it, so perhaps you need to look at vCLI to help you run these commands. What is admin.sh trying to do, if we knew that we could help find an alternative that does work without the use of SSH.


Best regards,
Edward L. Haletky VMware Communities User Moderator, VMware vExpert 2009

Now Available: 'VMware vSphere(TM) and Virtual Infrastructure Security'[/url]

Also available 'VMWare ESX Server in the Enterprise'[/url]

Blogging: The Virtualization Practice[/url]|Blue Gears[/url]|TechTarget[/url]|Network World[/url]

Podcast: Virtualization Security Round Table Podcast[/url]|Twitter: Texiwll[/url]

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
0 Kudos
Sureshadmin
Contributor
Contributor

Thank You @texiwill @c_shanklin

Thanks for evaluating my query and answering it.

Can this be done?

I have one Linux VM where all the RSA keys for ESX boxes are installed. Can a shell script be written to trigger that admin.sh in all esx boxes given the list of esx boxes via text file. This script just collect some details of ESX hardware and datastore details.

Can you please help me giving a shell script?

Thanks in advance!

0 Kudos
lldmka
Enthusiast
Enthusiast

Hi,

We occasionally use the attached scripts to trigger commands across our fleet of 38 ESX hosts, via SSH from a central Windows box. They use plink, as mentioned above by Edward, and as currently written require root access to SSH.

The scripts may be messy (I'm not a script guru), but work well. Note, be very careful as the command will be run across all hosts.

updinit.txt (change to .cmd) - initiates the process and sets up logging

esxhosts.txt - the list of target ESX hosts

esxupd.txt (change to .cmd) - establishes the plink connection and runs the desired command

Mark

0 Kudos