Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

perl : $ssh->waitfor

by user786 (Sexton)
on Jun 20, 2014 at 00:28 UTC ( [id://1090530]=perlquestion: print w/replies, xml ) Need Help??

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

I'm new to programming. I have written a perl script which does the following. 1) ssh into a remote machine 2) execute a sequence of commands. The script requires user interaction in between.It needs user name and password. I'm not sure how to proceed with that.

use Net::SSH::Expect; use strict; use warnings; #login to a remote host my $ssh = Net::SSH::Expect->new (host => "ipaddr", password=> 'pwd', user => 'username', raw_pty => 1); my $login_output = $ssh->login();

The login is successful. Now, for the below scp command i'm prompted to enter the username and password of that system. Enter usename for remote scp server: Enter the password for the remote server: The script stops here. This is what i tried.but no luck

my $cpscp = $ssh->exec("copy scp install ip addr filename"); my $usr = $ssh->waitfor ("Enter usename for remote scp server:\s*\z ", + 5); if ($usr) { print("string found \n"); my $pwd =$ssh->send("root"); } else { print("No string found\n"); }

The script is unable to identify it. "no string found" I also tried the following

$ssh->waitfor('Enter username for remote scp server:\s*\z ', 5) or die + "not found"; $ssh->send("root");

Replies are listed 'Best First'.
Re: perl : $ssh->waitfor
by roboticus (Chancellor) on Jun 20, 2014 at 13:05 UTC

    user786:

    The Net::SSH::Expect module documentation mentions the before function in the waitfor description. It appears that you can use that function to show what was sent to you. I'd suggest making that part of your error message, so you can see how it differs from what your regex specifies.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1090530]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found