Solved

How to Run Execuatble Script from Desktop

  • 13 September 2019
  • 4 replies
  • 1638 views

Userlevel 2
Badge +2
Hi. I am fairly new to scripting especially with Nutanix. I can do Powershell scripting just fine but making the conversion to shell scripts has my brain in a knot. I have some acli commands to create a new vm, create a new Disk and a new NIC but I was unsure how to run them as an executable from my Windows desktop. Our cluster is Nutanix AHV.



So I run this from a command line to open putty and connect. It works fine without the script.

putty.exe -ssh admin@xxx.xxx.xxx.xxx -pw ****** -m "C:\newVM.sh"



The script is:

acli;

#creates a clone of Server2016

#vm.clone aTest clone_from_vm="Server2016RefImage" memory=8G num_cores_per_vcpu=2 num_vcpus=2;



#creates a D drive

# vm.disk_create aTest bus=scsi create_size=200G index=1 container="Container-1";



#Add a NIC

#vm.nic_create aTest connected=true network="Vlan6";



Each line will run fine if I run it in putty but I am not sure if I am stringing the commands together correctly. If I try to execute the script it opens the putty session then freezes.



Am I just barking up the wrong tree? Is there somewhere I can go for some basic knowledge for this? Some youtube videos or something on Pluralsight? The nutanix documentation can only get me so far and other than that and here I can find no other resources for Nutanix. Sorry for the newbie question but I am stumped.
icon

Best answer by galad2003 17 September 2019, 16:05

View original

This topic has been closed for comments

4 replies

Userlevel 2
Badge +2
So I figured out to pass a command by putting acli in front of the command. That solves the freezing issue I was having. So this works.

acli vm.clone aTest clone_from_vm="Server2016RefImage" memory=8G num_cores_per_vcpu=2 num_vcpus=2;



I can get them to run now using putty or plink, there seems to be no difference but what I can't do now is run multiple commands one after another. It will now clone my existing VM but I can't get it to add the hard drive or NIC from a script.



Do I need to add in a time delay between commands? Maybe this is something that would work better with a product like Ansible?



Ideally I would like to just have the script prompt me for a VM name and IP when I run it.



If there is a better way to do this please let me know. Again, I am used to running PS scripts from my laptop to a server and they execute the script. I am just trying to do the equivalent shell commands and I am just not that well versed in shell scripting.



I see Nutanix has PS commandlets but I have not gotten that to work in our environment yet and the ACLI are so elegant I hate to not use them.
Userlevel 1
Badge +3
To pass commands programmatically to a puTTY sessions you may want to try plink. It is available from the same site, and you can pass commands as a script that you want to execute. This will likely work better for you.



Here are some examples to help out:

https://www.thegeekstuff.com/2017/05/putty-plink-examples/



Enjoy!
Userlevel 2
Badge +2
I figured it out. I had a typo in the other lines. Putting ACLI in front of each command allows it to run. Using ; or && will also allow it to run one command after another. Thanks for the help.
Userlevel 1
Badge +3
I'm glad you figured it out. That's great news!