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

in which module?

i have already tried the module net::ssh:expect. but i need the script on several servers (linux 32bit, linux 64bit, solaris) on which i have not root access. so i try to keep it simple and don't use any module and especially not the net::ssh:expect module which has a dependency on IO::Tty which uses a shared library (tty.so).

  • Comment on Re^2: execute multiple commands over ssh (without module)

Replies are listed 'Best First'.
Re^3: execute multiple commands over ssh (without module)
by salva (Canon) on Feb 06, 2012 at 12:09 UTC
    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).

      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.