Operating System - Linux
1830242 Members
2426 Online
109999 Solutions
New Discussion

Re: Batch SSH from linux to Windows

 
Shailesh P Joshi
New Member

Batch SSH from linux to Windows

Hello,

We have few Apache web-servers running on 3-4 Windows machines. We are planning to monitor those machines from a linux box. We check whether the web-site is up/down by using "wget" and then if the site is down, send mail alerts.

In addition to sending alerts, we would like to restart the web server if the site is down. We thought, the best way would be to set up freeSSHd server on Windows box and connect to windows from Linux using public-private keys and then execute some batch script located on Windows.

We have successfully set up the keys, so that we can connect to windows without specifying the password. But when I try to execute following command for testing -

ssh -l <ls -lart
EOF

its giving error -
"Pseudo-terminal will not be allocated because stdin is not a terminal."

I tried changing 'command line shell' in freeSSHd to cygwin.bat. But the problem still exists.

I tried to search on net, but did not find any post related to this.

Is this possible? Or we are trying to achieve something impossible?

Thanks for the help.

Regards,
Shailesh
6 REPLIES 6
Ivan Ferreira
Honored Contributor

Re: Batch SSH from linux to Windows

I wonder if the command is executed, try with a batch command, like this:

ssh -l <ls -latr > ls.log 2>&1 &
EOF

Verify if the ls.log file is executed. Now, if you are success, how do you plan to stop the service? The net stop command won't be in cygwin I think. Windows 2003 have service recovery configuration.

Maybe, you can also enable telnet services on windows and use expect scripts to logon to the server and restart the service.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Stuart Browne
Honored Contributor

Re: Batch SSH from linux to Windows

Ivan, under Cygwin, you still have access to the standard dos/windows commands.

As for the other, why don't you use the form:

ssh -l "ls -lart"

You can stack the commands as well:

ssh -l "cd /;ls -lart;/cygdrive/c/Windows/system32/net.exe ..."

One long-haired git at your service...
Bill Thorsteinson
Honored Contributor

Re: Batch SSH from linux to Windows

Try adding the -T option to your ssh command.
This will disable pseudo-terminal allocation
which you shouldn't need for your script.
Sergejs Svitnevs
Honored Contributor

Re: Batch SSH from linux to Windows

Try to add "-f -t" options:
# ssh -f -t -l <
This should fork ssh into background and force pseudo-tty allocation just before command execution.

Regards
Alan_152
Honored Contributor

Re: Batch SSH from linux to Windows

I personally use expect in situations like this...
Andrea Rossi
Frequent Advisor

Re: Batch SSH from linux to Windows

I use cygwin.