#!/usr/bin/perl
use strict;
use warnings;
my $username = '$ARGV[0]';
my $password = '$ARGV[1]';
use Net::SSH::Expect;
my $ssh = Net::SSH::Expect-> new (
host => "10.38.228.230",
password => "lsxid4",
user => "root",
raw_pty => 1,
timeout => 10,
log_file => "log_file"
);
my $login_output=$ssh->login();
if ( $login_output =~ /Last/ )
{
print "The login for ROOT was successful, Let's see if we can change the password \n";
$ssh->send("passwd $username");
$ssh->waitfor ('password:\s*', 10) or die "Where is the first password prompt??";
$ssh->send("$password");
$ssh->waitfor ('password:\s*', 10) or die "Where is the Second password promp??";
$ssh->send("$password");
$ssh->waitfor('passwd:\s*',5);
print "The password for $username has been changed successfully \n";
}
else
{
die "The log in for ROOT was _not_ successful.\n";
}
我正在尝试通过以 root 身份登录到主机来更改远程主机上的用户密码,但 $username, $password
如果我在其工作的代码中提供硬编码值,似乎并没有采用这些值。
在命令行上像这样运行:
bash-3.00# ./test6.pl rak xyz12
The login for ROOT was successful, Let's see if we can change the password
Where is the first password prompt?? at ./test6.pl line 22.
bash-3.00#
如何远程更改用户密码