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

is there a way to execute multiple ssh commands on a remote host and save each command output in a different scalar without using a module? i want execute all commands in the same ssh connection. i have tried to do something like that, but i don't know how to save the output in a scalar. is there a way to do that in this manner?

$check = <<'CMD'; for i in /home/* do echo $i done CMD open(SSH, "| ssh sshtest\@localhost -T"); print SSH $check; close(SSH) or die "$!";

Replies are listed 'Best First'.
Re: execute multiple commands over ssh (without module)
by moritz (Cardinal) on Feb 06, 2012 at 10:42 UTC

      yes core modules are ok

Re: execute multiple commands over ssh (without module)
by Anonymous Monk on Feb 06, 2012 at 10:45 UTC

    is there a way to execute multiple ssh commands on a remote host and save each command output in a different scalar without using a module?

    Yes, look inside the module to see how its done

    or better yet, install the module

    A Guide To Installing Modules

    Yes, even you can use CPAN

      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).

        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).