Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to orchestrate some script tasks among few Linux machines and a Windows machine. ssh works fine for linux machines suing below:

ssh mysuser@targetLinuxmachine "python '/pathtomyscript/myscript.py' &"

But the same method doesn't work as background task when I'm sending the command to an Windows machine. On the Windows machine, I have ssh server running and the ssh connection itself is working. RSA public key has been inserted too. In fact below commands runs:

ssh -n -f mysuer@targetwinmachine "python 'C:\Windowspath\myscript.py -someswitch parameter' &"

however executing the command in bash will take my terminal to windows console and doesn't allow me to run it as a back ground task. I guess "&" is not working on windows to run the command as a background task.

How can I run the equivalent script on a Windows machine as a background task?

share|improve this question
    
To open an SSH session to a Windows host you need to run an SSH server on the target host. There are a number of commercial options which are easily googleable. Cygwin, although wonderful in many ways, is not fit for production use for a number of solid reasons, also googleable. –  ErikE Feb 19 at 17:19
    
I should have made the question a bit more clear, the ssh itself is working. I have ssh server running and below commands runs: 'ssh -n -f mysuer@targetwinmachine "python 'C:\Windowspath\myscript.py -someswitch parameter' &" ' just this takes my terminal to windows console and doesn't allow me to run it as back ground task. –  MRK Feb 19 at 18:02

4 Answers 4

up vote 2 down vote accepted

Yes, cygwin has a very good ssh server for windows. First you should download and install this.

After you can log into your windows machine with command line ssh, you can use ssh-keygen to make this passwordless and automatic.

The third thing were to install python on your windows machine, which you can get from http://www.python.org/getit/windows/ .

It is for me uncelar, which one of this steps don't work, but probably your main problem is with the ssh server install on your windows machine. Can you log in to your server with commandline ssh from your unix/linux box? If not, please upgrade your question and I will upgrade my answer.

share|improve this answer
    
Thanks but I already have ssh server running with rsa key. I'm sorry that my original post wasn't clear enough, the command it self runs but moves my linux terminal to windows terminal like an interactive mode. I need this command running in background so the other task under the line can continue without waiting for the windows task complete. –  MRK Feb 20 at 10:40
    
@MRK I can't understand this: "moves my linux terminal to windows terminal like an interactive mode." –  Peter Horvath Feb 20 at 10:45
    
When I run the line of ssh script, which I posted above, from a Linux machine, the Linux "user@lix:~$" prompt changes to "c:/" prompt and starts the script I listed after the ssh. Then, the C prompt remain as it is until the all intended python scripts complete. –  MRK Feb 20 at 10:50
    
@MRK This is the problem of your ssh server. I suggest to try the sshd from cygwin. –  Peter Horvath Feb 20 at 10:55
    
Really? that's a good news, I will try different types today. I'll update this soon. thanks. –  MRK Feb 20 at 11:00

So you just want to run the command in the background on linux? I think you're just putting the & in the wrong place. Put the & outside of the "":

ssh -n -f mysuer@targetwinmachine "python 'C:\Windowspath\myscript.py -someswitch parameter' " &
share|improve this answer
    
This is the tricky part of my problem. I'd like to send this code from Linux machine to run on Windows machine as a back ground task. Basically I'm forking 26 tasks in same time, then happen one have to run on Windows.... –  MRK Feb 20 at 10:37

Via the cgi scripts from an apache server is a nifty way to execute code on another machine.

share|improve this answer
    
Actually I tried with Python proxy to do the same, the problem is that my environment require to keep low in the memory footprint and keep running the waiting call through http wasn't really good method, that's how I'm ending up using this ssh and rsync method. –  MRK Feb 20 at 10:45

You can use Putty from a command line:

plink mysuser@targetLinuxmachine "python '/pathtomyscript/myscript.py' &"

SSH keys can be managed via PuttyAgent.

share|improve this answer
    
Actually I have putty on Windows server side, but I didn't know the putty works as ssh server. Therefore I installed SharpSSH. That's anyway good to know thanks! –  MRK Feb 20 at 10:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.