Posted to tcl by urthmover at Mon Aug 08 18:03:03 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 abcdefg
- set newpassword 1234567
- set cmd "passwd root"
- spawn ssh $user@$line
-
- expect "*continue*" # is there a way to only do this if the question is asked?
- send -- "yes\r"" # this will be the answer if the above question is asked
-
- 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;
- }