User Tools

Site Tools


kurs:passwort_aendern

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

kurs:passwort_aendern [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +use Net::​SSH::​Expect;​
  
 +$curr_pwd = '​test';​
 +$new_pwd = '​blablablabla';​
 +
 +my $ssh = Net::​SSH::​Expect->​new (
 +     host => "​localhost",​
 +     ​password=>​ $curr_pwd,
 +     user => '​test',​
 +     ​raw_pty => 1
 +   );
 +
 +my $login_output = $ssh->​login();​
 +if ($login_output !~ /Last login/) {
 +       die "Login has failed. Login output was $login_output";​
 +    }
 +
 +# my $ls = $ssh->​exec("​ls -l /");
 +# print($ls);
 +$ssh->​send("​passwd"​);​
 +$ssh->​waitfor('​password:​\s*\z',​ 1) or die "​prompt '​password'​ not fou
 +nd after 1 second";​
 +$ssh->​send($curr_pwd);​
 +$ssh->​waitfor(':​\s*',​ 1) or die "​prompt 'New password:'​ not found";​
 +$ssh->​send($new_pwd);​
 +$ssh->​waitfor(':​\s*',​ 1) or die "​prompt '​Confirm new password:'​ not found";​
 +$ssh->​send($new_pwd);​
 +# check that we have the system prompt again.
 +my ($before_match,​ $match) = $ssh->​waitfor('>​\s*',​ 1);  # waitfor() in a list context
 +        die "​passwd failed. passwd said '​$before_match'​."​ unless ($match);
 +
 +# closes the ssh connection
 +$ssh->​close();​
 +</​code>​
kurs/passwort_aendern.txt ยท Last modified: 2014/09/10 21:22 (external edit)