#!/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";
}
ルートとしてホストにログインすることでリモートホストのユーザーパスワードを変更しようとしてい $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#
ユーザーのパスワードをリモートで変更するにはどうすればよいですか