我想知道如何在expect [qr /../]命令中使用变量
我试过了:
my $hostname = $ARGV[3];
my $quotedhostname = quotemeta($hostname);
$exp->spawn("ssh -o ConnectTimeout=$connectTimeout $user\@$ip") or die ("unable to spawn \n");
@obj=$exp->expect( $commandTimeout,
[ qr/[Pp]assword:\s*/ => sub
{
print "password sent";
my $exp = shift;
$exp->send($passwdused, "\n"); #ecriture du mot de pass routeur
$exp->expect($commandTimeout2,);
exp_continue;
}
],
[ qr/.*$quotedhostname.*/ => sub
{
print "hostname captured"
$exp->send("term length 0", "\n");
$exp->expect($commandTimeout2,);
executeCommands();
}
]
);
但是Expect并不理解$ hostname是一个正则表达式。