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

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;

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