【发布时间】:2014-06-20 11:04:56
【问题描述】:
我是编程新手。我编写了一个 perl 脚本,它执行以下操作。
1) ssh 进入远程机器
2) 执行一系列命令。
脚本需要用户交互。它需要用户名和密码。我不知道该怎么做。
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();
登录成功。现在,对于下面的 scp 命令,系统会提示我输入该系统的用户名和密码。脚本在这里停止。
my $cpscp = $ssh->exec("copy scp install ip addr filename");
Enter usename for remote scp server:
Enter the password for the remote server:
输入用户名后,我需要输入密码。这是我所做的,但没有成功。
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");
}
脚本无法识别它。 “没有找到字符串”
我也尝试了以下
$ssh->waitfor('Enter username for remote scp server:\s*\z ', 5) or die "not found";
$ssh->send("root");
【问题讨论】:
标签: regex perl perl-module cpan