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");