linux - Python try and except in launching password less ssh connection -
i want know whether scenario of taking ssh works or not try , except. if try part ask ssh password should move except part. here code,
import os,sys,subprocess def process (input): print input = subprocess.popen (input,shell=true,stdout=subprocess.pipe,stderr=subprocess.pipe) output,error = a.communicate() return output,error try: process('ssh system1@123.123.123.123 \'ls\'') except: process('ssh system2@10.101.10.1 \'ssh system1@123.123.123.123 \'ls\' \'')
in case not working @ ssh time out.
as wrote it won't, because ssh
sit there waiting password , not fail.
however since not sending input command, can pass -n
option ssh
, fail if wanted ask anything. -n
should work.
Comments
Post a Comment