VMware Cloud Community
Kyrius
Contributor
Contributor
Jump to solution

How can I power-on a VM from a Windows batch file?

I'm desperatly trying to find out a way to forward a command to an ESX server in order to power on a virtual machine. This is needed by a backup post-command (a Windows .cmd file) that must be executed on the VCB server to start the VM up after a cold backup.

I'm testing Plink to forward the following command to the ESX server by SSH:

vmware-cmd /vmfs/volumes/47012243-1dadf644-000bcdee702d/VMACHINE/VMACHINE.vmx start

There are 2 problems:

1- I'm not able to understand how forward the command from my batch file to ESX using plink.exe

2- In any case the "vmware-cmd" command needs root's privileges to be executed

I would be grateful if someone would be kind enough to post me some precious suggestions.

0 Kudos
1 Solution

Accepted Solutions
merse
Hot Shot
Hot Shot
Jump to solution

You can edit the /etc/ssh/sshd_config file and change PermitRootLogin to yes, save the file then restart the sshd service:

nano -w /etc/ssh/sshd_config

CTL + X (to exit)

Y (to save)

Enter (to overwrite existing file)

then from the console:

service sshd restart

View solution in original post

0 Kudos
8 Replies
merse
Hot Shot
Hot Shot
Jump to solution

What is the full plink command line you're running?

0 Kudos
Jasemccarty
Immortal
Immortal
Jump to solution

As root... This will work...

plink -ssh root@vmhost -pw password vmware-cmd /vmfs/volumes/47012243-1dadf644-000bcdee702d/VMACHINE/VMACHINE.vmx start

That is, if root has ssh privileges.

If is doesn't, you'll need to use the -m option, and read your commands from a file. That way, you can ssh as a non-privileged user, SU, and then run your command...

Hope that helps.

Jase

Jase McCarty - @jasemccarty
jccoca
Hot Shot
Hot Shot
Jump to solution

Hi,

If you have ssh command line from your windows machine you can do the following:

ssh "vmware-cmd /vmfs/volumes/47012243-1dadf644-000bcdee702d/VMACHINE/VMACHINE.vmx start"

0 Kudos
merse
Hot Shot
Hot Shot
Jump to solution

I would consider setting up a limited user using sudo that only has the ability to run vmware-cmd.

Guide to editing the sudo file is here:

http://www.xtravirt.com/index.php?option=com_remository&Itemid=75&func=startdown&id=10

Then you can use plink with the user's password rather than putting the root password in a batch file.

Kyrius
Contributor
Contributor
Jump to solution

Thanks to all of you. You're very kind.

This is the command I used:

plink -ssh sesxf1.admain.loc -l root -pw rootpsw vmware-cmd /vmfs/volumes/47012243-1dadf644-000bcdee702d/VMACHINE/VMACHINE.vmx start

I think the following is quite the same:

plink -ssh -pw rootpsw vmware-cmd /vmfs/volumes/47012243-1dadf644-000bcdee702d/VMACHINE/VMACHINE.vmx start

They both give me "access denied". I suppose this means that the root hasn't got the right privileges for grant direct access via SSH. Infact, using Putty, I've first to connect as another user and the, by typing the "su -" command, grant access as root.

I'd rather prefer not using the -m option cause it means adding / removing script files in all the esx's server every time I add or remove an host in / from the backup system.

To be honest, I don't know how to logon as user then SU- and finally run my command. Not using a batch file...

Do you know how set root up to grant direct access to SSH without using "SU -" ?

Sorry for being so newbie...

0 Kudos
merse
Hot Shot
Hot Shot
Jump to solution

You can edit the /etc/ssh/sshd_config file and change PermitRootLogin to yes, save the file then restart the sshd service:

nano -w /etc/ssh/sshd_config

CTL + X (to exit)

Y (to save)

Enter (to overwrite existing file)

then from the console:

service sshd restart

0 Kudos
Kyrius
Contributor
Contributor
Jump to solution

I modified the sshd_config as merse explained.

Now the command works great!

Thank you very much!

0 Kudos
doepain
Contributor
Contributor
Jump to solution

I don't seean /etc/ssh directory. How can we achieve this on ESXi update3?

Senior Hosting Engineer

ModusLink Open Channel Solutions, Inc.

Senior Hosting Engineer ModusLink Open Channel Solutions, Inc.
0 Kudos