Skip to content

Instantly share code, notes, and snippets.

@elcontrastador
Created September 18, 2011 23:30
Show Gist options
  • Save elcontrastador/1225711 to your computer and use it in GitHub Desktop.
Save elcontrastador/1225711 to your computer and use it in GitHub Desktop.
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