I have a python script on a remote machine which I want to execute from my local machine. It takes in a few arguments and this is how I would run it if I were to run it on that machine.
python python_parallel.py --num=10 --ssh=/home/user1/path/file.txt
Currently I have a python code in my local machine which 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 [email protected] python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) )
Is there a better way of doing this? I tried the solution at this link, but it gave me an error "ImportError: No module named ssh"
I recommend you look at the plumbum module for doing things like this.
Its a pretty cool and easy way to run local commands and you can do the same with remote commands quite easily (with a context manager).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With