Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing exe or bat file on remote windows machine from *nix

I am trying to execute a bat file on remote windows machine on cloud from my Linux. The bat files starts selenium server and then my selenium tests are run. I am not able to start selenium RC server on that machine. I tried with Telnet but the problem with it is when telnet session is closed the RC server port is also closed. As my code my code has to start the server so I tried with ANT telnet task and also executed shell script of telnet in both ways the port was closed.

I read about Open SSH, psexec for linux and cygwin. But i am not getting how to use these and will they will solve my problem.

I have tried to start a service which will start the server but in this method i am not getting browser visible all tests are running in background as my script takes screen shot browser visibility is must.

Now my Question is what to use and which will be preferable for my job. and what ever i choose should be executed by code it may be by shell, ant or php.

Thanks in advance.

like image 204
lAH2iV Avatar asked Aug 12 '11 06:08

lAH2iV


2 Answers

I've succeeded to run remote command on W2K3 via EXPECT on Debian Buster. Here is the script of mine:

#!/usr/bin/expect
#
# execute the script in the following manner:
#
#      <script>   <vindoze>   <user>  <password>   <command>
#
#
set timeout 200

set hostname [lindex $argv 0]
set username [lindex $argv 1] 
set password [lindex $argv 2]
set command  [lindex $argv 3]

spawn telnet $hostname

expect "login:"
send "$username\r"
expect "password:"
send "$password\r"

expect "C:*"
send "dir c:\\tasks\\logs \r"
# send $command

expect "C:*"
send "exit\r\r\r"

Bear in mind that you need to enable TELNET service of the Win machine and also the user which you are authenticated with must be member of TelnetClients built-in Win group. Or as most of the Win LazyMins do - authenticate with Admin user ;)

I use similar "expect" script for automated collecting & backup configuration of CLI enabled network devices like Allied Telesyn, Cisco, Planet etc.

Cheers, LAZA

like image 89
LAZA Avatar answered Oct 07 '22 01:10

LAZA


I prefer to use cygwin and use SSH to then log in to the windows machine to execute commands. Be aware that, by default, cygwin doesn't have OpenSSH installed.

Once you have SSH working on the windows machine you can run a command on it from the Linux machine like this:

ssh user@windowsmachine 'mycommand.exe'

You can also set up ssh authentication keys so that you don't need to enter a password each time.

like image 39
Lee Netherton Avatar answered Oct 07 '22 00:10

Lee Netherton