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

Hello, I am using Expect and perl to send commands to a ssh session and I now want to run a couple of commands from the command line on the machine where I am running the perl script. I have tried the code below and it does not seem to be sent to the local command line. Is there anyway of co nfirming it is actually being sent to the local command line. I know it is a simple question but I just can't see why it is not being run? thanks for help
my $exp = new Expect; #commands below are not being sent to the local machine command line a +nd not sure why not? $exp->send("ssh root\@device203 install license < input/Licence321178. +lic\r"); print "$exp\n"; sleep(1); $exp->send("admin\r"); sleep(1); # This next section uses Expect and SSH successfully my $ssh = Net::SSH::Expect->new ( host => "$host_details[1]", user => 'root', password => 'admin', raw_pty => 1, timeout => 1 ); #eval { my $login_output = $ssh->login(); if ($login_output !~ /loginprompt/) { die "Login has failed. Login output was $login_output"; }

Replies are listed 'Best First'.
Re: mixing perl expect ssh and local commands
by Sewi (Friar) on Sep 03, 2009 at 12:14 UTC
    Common SSH clients read the password from the TTY, not from STDIN. Try using a certificate to authenticate yourself or check (man ssh or ssh --help) if your SSH client could be forced to read the password from STDIN.

    Note that your program contains clear-text password and due to this it is a high security risk.