I need to ssh into the server and execute few commands and process the response using subprocess. Here's my code
command = 'ssh -t -t buildMachine.X.lan; sudo su - buildbot ; build-set sets/set123'
print "submitting command"
result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
print "got response"
response,err = result.communicate()
print response
This is getting stuck. I have seen other threads talking about passing a list instead of string to subprocess and removing shell=True.. I did that too but didn't work.
Ultimately I need the result of last command i.e. build-set in order to extract some information out of it.. help?
sshas the last argument, not as additional commands separated by;.ssh host 'foo bar'to runfoo barremotely. If you dossh host; foo baryou're runningssh hostlocally, waiting forsshto exit, then executingfoo barlocally.shell=True. It's hard enough to figure out how to split upssharguments vs. remote-host arguments without having to deal with an extra layer of quoting.