Im a new bie to python programming and writing a script to login to a linux machine (from a server) and check for connectivity to multiple IPs in a quick manner. i came across this thread Multiple ping script in Python which uses subprocess.Popen and does it fast but it does check for ping from the server where the script is run rather than the linux machine
I have the code to ssh to the linux machine and get its handle. snippet below is there a way to pass on this handle to the subprocess.Popen so that the ping can be checked from the linux machine instead of the server.
I tried to read the documentation of subprocess.Popen but could not get a clarity.
kindly help.
ssh = SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_system_host_keys()
for x in range(retries):
try:
ssh.connect(ip, username = username , password = password)
log.info('Connected to the machine {0} successfully..'.format(ip))
return ssh
except (paramiko.BadHostKeyException, paramiko.AuthenticationException, paramiko.SSHException, socket.error) as e:
log.info('Exception : {0}'.format(e))
return False
I used the code using subprocess.call() from the same link pasted above but that is not quick enough..
any help would be greatly appreciated.