我希望在运行安装脚本时自动输入密码.我使用Perl中的反引号调用了安装脚本.现在我的问题是如何使用expect
其他输入密码?
my $op = `install.sh -f my_conf -p my_ip -s my_server`;
Run Code Online (Sandbox Code Playgroud)
执行以上操作时,将打印一个密码行:
Enter password for the packagekey:
Run Code Online (Sandbox Code Playgroud)
在上面这行我想输入密码.
dsm*_*dsm 12
使用Expect.pm.
该模块专为需要用户反馈的应用程序的程序控制而定制
#!/usr/bin/perl
use strict;
use warnings;
use Expect;
my $expect = Expect->new;
my $command = 'install.sh';
my @parameters = qw(-f my_conf -p my_ip -s my_server);
my $timeout = 200;
my $password = "W31C0m3";
$expect->raw_pty(1);
$expect->spawn($command, @parameters)
or die "Cannot spawn $command: $!\n";
$expect->expect($timeout,
[ qr/Enter password for the packagekey:/i, #/
sub {
my $self = shift;
$self->send("$password\n");
exp_continue;
}
]);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15720 次 |
最近记录: |