Posted to tcl by urthmover at Mon Aug 08 15:01:59 GMT 2011view raw

  1. #!/usr/bin/expect
  2.  
  3. set f [open hosts.lst r]; # open the file
  4. set data [read $f]; # read the file content
  5. close $f; # close the file
  6. foreach line [split $data \n] { ;# starts a loop over the lines
  7. if {$line eq {}} continue; # ignore blank lines
  8. set user root
  9. set oldpassword abcdefg
  10. set newpassword 1234567
  11. set cmd "passwd root"
  12. spawn ssh -n $user@$line
  13.  
  14. expect "*?ssword:*"
  15. send -- "$oldpassword\r"
  16.  
  17. send -- "$cmd\r"
  18. expect "*?ssword:*"
  19. send -- "$newpassword\r"
  20. expect "*?ssword:*"
  21. send -- "$newpassword\r"
  22.  
  23. send -- "exit\r"
  24. send -- "\r"
  25.  
  26. expect eof;
  27. }