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

Is there a possibility to create a two way connection with the server using perl program? i mean i have tried this code here

#!/usr/bin/perl use Net::SSH::Perl; my $host = "IP_adress"; my $user = "user"; my $password = "password"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass)

this creates a one way connection is there a method to create a two way connection and implemet commands on the host system ?

Replies are listed 'Best First'.
Re: a perl program to create two way connection with the server
by atcroft (Abbot) on Mar 18, 2015 at 14:22 UTC

    Your last line ("this creates a one way connection...") is incorrect-what you have done at that point is to make a connection to the remote server and authenticate. At that point, you can then do the following (adapted from the Net::SSH::Perl documentation):

    my($stdout, $stderr, $exit) = $ssh->cmd($cmd); # ... other code here ... $ssh->cmd($cmd); # ... other code here ...

    Hope that helps.

Re: a perl program to create two way connection with the server
by Anonymous Monk on Mar 18, 2015 at 12:56 UTC

    A SSH connection already is a two-way connection, and it is possible for the server to execute commands on the client - all that needs to be done is the client needs to read the commands from the server and execute them. But maybe you're looking for SSH tunneling (I believe Net::OpenSSH supports this)? It's unclear to me what exactly you want to do, perhaps you could explain or give examples?

      say for example i want to reboot the server, is it possible with net::open::ssh

        So is this thread about "two-way connections" or is it a repeat of your last two threads reboot a system (machine or server) multiple times with perl script?

        Anyway, yes, it is possible, given that the user you are connecting to the server with has the permissions to do so (via sudo or directly). A quick, untested copy & paste from the Net::OpenSSH docs, which you should read:

        use Net::OpenSSH; my $ssh = Net::OpenSSH->new($host); $ssh->error and die "Couldn't establish SSH connection: ".$ssh->error; $ssh->system("sudo reboot") or die "remote command failed: ".$ssh->error;
        A reply falls below the community's threshold of quality. You may see it by logging in.
        How is that related to bidirectionality?

        Your questions are unclear. Take your time to fully describe your problem, the environment and what you are trying to achieve and then we may be able to help you.

Re: a perl program to create two way connection with the server
by afoken (Chancellor) on Mar 19, 2015 at 17:45 UTC