Adler has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, in my program i wrote, i use Net::SSH::Perl module. I can open ssh connection and do what i want, but what i dont know is how to close my ssh connection. i tried close( $ssh) and $ssh->close, but it doesnt work. i searched a bit in the net, and i saw that i need to let to connection to reach its timeout and then it ill be closed. I would like to know if at present there is a way to close ssh connection? if still not, how could i check if my ssh connection is still open? Thanks

Replies are listed 'Best First'.
Re: how to close shh connection
by gemoroy (Beadle) on Nov 14, 2009 at 08:51 UTC
    I am not sure about perl implementation,

    but ssh->cmd("exit") should do the trick, it is an applied ssh level command, not a module method level so it should work in warper one

    I think connection is present till $ssh->session_id is defined =)

      ssh->cmd("exit") will do mostly nothing.

      The proper way to close the connection is to undefine the $ssh variable, or just to let it go out of scope:

      undef $ssh;