in reply to SSH and expect without module

Hello touriste75,

I would start with (How To Configure SSH Key-Based Authentication on a Linux Server).

Update: Forgot to say, by using SSH-keys you don't need to enter a password to connect to your remote host. Really you should do this even if you can use Perl modules.

As a second step a few days ago another Monk asked similar question, and he post a piece of code that seems to be working according to him (untested by me). Find more about it here (SSH and qx).

From the similar question (SSH and qx) as salva the author of Net::OpenSSH suggested: Net::OpenSSH is a pure Perl module. You just have to copy everything in the lib directory from the module distribution into some directory in the machine and add that directory into @INC to get it working..

Update2: In the past I had similar problems I tested any possible way of ssh, telnet modules that I could find. Take a look with working codes examples Best module to execute administrator commands on external operating systems (Linux).

Recently also another monk was asking for something similar (been able to SSH to multiple nodes). I created a working example for him with Net::OpenSSH::Parallel and the example is multiple machines disk space alert.

Similarly if you want to execute also SUDO commands, including example with working code Net::OpenSSH::Parallel with sudo commands.

Hope this helps, maybe to have another approach to your problem.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: SSH and expect without module
by cbeckley (Curate) on Mar 15, 2017 at 20:54 UTC

    The Monks here were kind enough to help me get Net::OpenSSH installed on an older system where updates were, uh, problematic. But I was further stymied by the age of the underlying ssh client, which was incompatible. So I offer the following:

    sub ops_do_ssh_qx { my ($cmd) = @_; $cmd->{ssh_cmd} = 'ssh ' . $cmd->{user} . '\@' . $cmd->{host} . ' +\'' . $cmd->{command} . '\'' . ' 2>/dev/null'; $cmd->{output} = qx($cmd->{ssh_cmd}); if ( defined $cmd->{output} ) { $cmd->{cmd_ret_code} = $?; chomp $cmd->{output}; } else { ($cmd->{ssh_ret_code}, $cmd->{ssh_ret_msg}) = (0 + $!, '' . $!); } return $cmd; }

    It does rely on ssh keys being setup properly.

    I hope you find it useful.

    Thanks,
    cbeckley