Posted to tcl by urthmover at Mon Aug 08 20:02:07 GMT 2011view raw
- #!/usr/bin/expect
-
- set f [open hosts.lst r]; # open the file
- set data [read $f]; # read the file content
- close $f; # close the file
- foreach line [split $data \n] { ;# starts a loop over the lines
- if {$line eq {}} continue; # ignore blank lines
- set user root
- set oldpassword [llength $argv 0]
- set newpassword [llength $argv 1]
- set cmd "passwd root"
- spawn ssh $user@$line
-
- expect continue {send -- yes\r;exp_continue}
-
- expect ssword
- send -- "$oldpassword\r"
- send -- "$cmd\r"
- expect "*?ssword:*"
- send -- "$newpassword\r"
- expect "*?ssword:*"
- send -- "$newpassword\r"
-
- send -- "exit\r"
- send -- "\r"
-
- expect eof;
- }