我正在尝试编写一个perl例程,该例程用于期望自动化我的rysnc命令。 Rsync处于守护进程模式,因此是“::”。我相信基于期望输出我的命令格式正确,但我不相信我的期望(返回)是正确的,因为我没有发送密码。
以下是整个例程:
sub file2SDB {
my $file = $_[0];
my $path = $_[1];
my $type = $_[2];
print "$file \n";
print "$path \n";
print "$type \n";
my $prompt = 'Password:';
my $passwd = 'xxx';
my $cmd = "$file file-manager\@localhost\:\:$path$type";
my $timeout=50;
my $ssh_exp = new Expect();
$ssh_exp->exp_internal(1);
$ssh_exp->raw_pty(1);
$ssh_exp->spawn("rsync", $cmd) or die "Cannot spawn rsync command: $!n";
my $response = ($ssh_exp->expect($timeout, 'Password:'));
if ($response) {
$ssh_exp->send($timeout, '-re', "$passwd") or warn "Password not sent...";
}
else {
print "No response from rsync command.\n";
print "$cmd\n";
}
$ssh_exp->soft_close();
}