Created
September 25, 2011 01:45
-
-
Save elcontrastador/1240103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.passwd(login,passwd) | |
outputs = Hash.new | |
#$expect_verbose = true | |
PTY.spawn("/usr/bin/passwd #{login}") do |gdb_out,gdb_in,pid| | |
gdb_out.expect(/^Enter new UNIX password: /,1) do |r| | |
gdb_in.printf("#{passwd}\n") | |
end | |
gdb_out.expect(/^Retype new UNIX password: /,1) do |r| | |
gdb_in.printf("#{passwd}\n") | |
end | |
outputs[:stdout] = gdb_out.expect(/^passwd: password updated successfully/,3) | |
if outputs[:stdout] =~ /success/ | |
outputs[:exitstatus] = 0 | |
else | |
outputs[:exitstatus] = 1 | |
end | |
outputs[:pid] = pid | |
end | |
outputs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment