Posted to tcl by urthmover at Mon Aug 08 20:02:07 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 [llength $argv 0]
  10. set newpassword [llength $argv 1]
  11. set cmd "passwd root"
  12. spawn ssh $user@$line
  13.  
  14. expect continue {send -- yes\r;exp_continue}
  15.  
  16. expect ssword
  17. send -- "$oldpassword\r"
  18. send -- "$cmd\r"
  19. expect "*?ssword:*"
  20. send -- "$newpassword\r"
  21. expect "*?ssword:*"
  22. send -- "$newpassword\r"
  23.  
  24. send -- "exit\r"
  25. send -- "\r"
  26.  
  27. expect eof;
  28. }