I’m interested in writing a script so that the only copy of the script resides on my local machine, but the script executes on remote machines, possibly with the remote machines executing the script on other remote machines (i.e., 2 or more levels of recursion in the distributed invocation tree).
One way to achieve this would be to copy the script to the remote machines in one step and then perform remote execution via ssh in a second step, passing appropriate parameters to the script, which will pass different parameters for each remote invocation, each of which would be performed via something like:
subprocess.call(['ssh', <user@address>, 'python scriptname.py <params>'])
Is it possible to achieve this in one step without first copying the python script. Obviously, I’d still have to transmit the code in the script as part of the remote call in some way, but it would be preferable not to have to run two separate commands and perhaps even a third to clean up the file from the remote machine after the script is run.
No, you won’t be able accomplish this in one step (except for
python -c 'print "hello world"'maybe). But fabric might make your life a little easier.