in reply to Re^2: execute multiple commands over ssh (without module)
in thread execute multiple commands over ssh (without module)

Try Net::OpenSSH, it's pure perl and doesn't require any other module (unless you want to use password authentication, in that case it also needs IO::Pty).
  • Comment on Re^3: execute multiple commands over ssh (without module)

Replies are listed 'Best First'.
Re^4: execute multiple commands over ssh (without module)
by dsx (Novice) on Feb 06, 2012 at 18:51 UTC

    Net::OpenSSH is a very nice module. but on the solaris server isn't installed OpenSSH. thats the problem.

    so now i have tested the following but it does not work. have anybody an idea?

    #!/usr/bin/perl -w use strict; use IPC::Open2; open2(*SSH_OUT, *SSH_IN, 'ssh -T localhost'); print SSH_IN "df -h"; my $df = <SSH_OUT>; print SSH_IN "du -sh"; my $du = <SSH_OUT>; print SSH_IN "exit"; print $df; print $du;
      You have to append "\n" to your command strings. You will also have to account for the shell prompt lines.

      If I recall correctly, IPC::Open2 already sets the file handles in autoflush mode. Otherwise, you will have to do it yourself.

      In any case, installing OpenSSH on Solaris is quite easy, precompiled packages are available from SUN freeware, and they only have a few dependencies. Talking to the shell is a flawed approach that would break when you least expect it.