- 论坛徽章:
- 0
|
在hpux上面,用perl中的expect工具来自动修改操作系统用户密码,出现的错误如下,手工执行passwd命令都是正常的。
Changing password for user111
pam_chauthtok: System error
====== 代码如下: ======
#!/usr/bin/perl -w
use Expect;
$flag=0;
$user=$ARGV[0];
$oldpassword=$ARGV[1];
$password=$ARGV[2];
$start=Expect->spawn("passwd",$user);
$start->expect(5,['Old Password:',sub {my $self = shift;
$self->send("$oldpassword\n");
$flag=1;
exp_continue;}],
['Old password:',sub {my $self = shift;
$self->send("$oldpassword\n");
$flag=1;
exp_continue;}],
['Enter existing login password:',sub {my $self = shift;
$self->send("$oldpassword\n");
$flag=1;
exp_continue;}],
['New password:',sub {my $self = shift;
$self->send("$password\n");
$flag=2;
exp_continue;}],
['New Password:',sub {my $self = shift;
$self->send("$password\n");
$flag=2;
exp_continue;}],
['Re-enter new password:',sub {my $self = shift;
$self->send("$password\n");
$flag=3;
exp_continue;}],
['Re-enter new Password:',sub {my $self = shift;
$self->send("$password\n");
$flag=3;
exp_continue;}],
['changed',sub {$flag=4;
exp_continue;}]);
if ($flag=='1') {
exit 1;}
elsif ($flag=='2') {
exit 1;}
elsif ($flag=='3') {
exit 1;}
elsif ($flag=='4') {
exit 0;} |
|