Start a process on another computer on the network
Question: I'm required to start a series of python scripts and/or other windows
executables. Some of these require a Windows system, others require a Linux
machine.

Currently there are designated machines to run the OS-dependent programs. So I
know where I want to start which program.

Is there a way to start a python script (or a windows executable) from a
python script, on the local network, on another computer (e.g. run
`192.168.0.101:/dir/python_script_123.py`?

The script, which should then run various programs may then look something
like this in _pseudo code_..

    
    
    linuxip = 192.168.0.101
    linuxparam = "required parameter"
    
    winip = 192.168.0.201
    winparam = "required parameter"
    
    #option 1 (run all), 2(run linux only), 3(run windows only), 4(run local only)
    option = 1
    
    if option == 1:
        magic_things.run("linuxip:/dir/linux_script.py" + linuxparam)
        magic_things.run("winip:C:\\dir\\windows_prog.exe" + winparam)
        subprocess.call(["/dir/local_script.py","parameter"])
        subprocess.call(["/dir/another_local_script.py","parameter"])
    elif option ==2:
        [...]
    


Answer: You need to connect to your client machines in any way. In chase of the linux
machine you could use SSH. see <http://en.wikipedia.org/wiki/Secure_Shell>

Assuming you have a ssh server on the linux client running you could use the
package paramiko (<http://docs.paramiko.org/en/1.15/api/client.html>) to
connect to the machine and run your script there.

This could look something like this:

    
    
    from paramiko.client import SSHClient
    
    client = SSHClient()
    client.load_system_host_keys()
    client.connect('linuxip', username='your_user', password='very_secret')
    stdin, stdout, stderr = client.exec_command('python /home/your_user/your/path/to/scripty.py')
    

However please note that its not very secure to store passwords in scripts and
you probably do better with a public/private key authentication (See the wiki
article).

The paramiko package also offers the option for an ssh server, so this might
be a solution for your windows machine, but I am very much not shure as I
don't run any windows any more.

Hope this was helpful!

David

