tags:

views:

95

answers:

2

I m using single object of paramiko.SSHClient() for executing a command on a remote machine.

so i m using ssh.exec_command(cmd)

But if the connection to remote host is lost, ssh.exec_command hangs up.

Is there a way to check for connection existence before ssh.exec_command()????

A: 

If you have a long running SSH connection, you may want to use the Keep Alive parameter via Transport.set_keepalive.

John Paulett
I tried that.I set_keepalive to 1.Now it shud send packet at interval of 1 sec and if connection is not available , it shud know it, and then Transport.is_active() shud return false.But strange is that, after that also , when network is not availbale, is_active() returning true. :-(I dont know why.
hima
A: 

As an alternate possibility, maybe execnet would work. It wraps the command line ssh command instead, so it's definitely not the paramiko approach... just a though.

Peter Hansen