Best way to run python script remotely

I have a python script on a remote computer that I want to execute from my local machine. It takes several arguments, and I would run it if I ran it on this machine.

python python_parallel.py --num=10 --ssh=/home/user1/path/file.txt 

I currently have python code on my local machine that runs the above script:

 from optparse import OptionParser parser.add_option("-n", "--num", type="int", dest="num_spice",help="Enter the number") parser.add_option("-s", "--ssh", dest="ssh_txt",help="Enter the path to the text file") num_spice=options.num_spice ssh_txt=options.ssh_txt (options, args) = parser.parse_args() os.system('ssh user1@10.100.10.201 python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) ) 

Is there a better way to do this? I tried the solution on this link , but it gave me the error "ImportError: No module ssh"

+4
source share
2 answers

I recommend that you look at the plumbum module to do this.

Its a pretty cool and easy way to run local commands, and you can easily do the same with remote commands (using the context manager).

+6
source

Do you find using Fabric ? It is really easy to use.

+2
source

All Articles