Change password on many linux

From Tuxunix
Jump to: navigation, search
 #!/usr/bin/expect -f
 
 set servername [lindex $argv 0]
 set usertomodify [lindex $argv 1]
 set NewPassword [lindex $argv 2]
 set timeout -1
 spawn sudo ssh [lindex $argv 0]
 expect "root #"
 send -- "passwd $usertomodify\r"
 expect "New password: "
 send -- "$NewPassword\r"
 expect "Re-enter new password:"
 send "$NewPassword\r"
 expect "successfully"
 send "exit\r"
 expect eof