Posted to tcl by urthmover at Mon Aug 08 18:03:03 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 $user@$line
  13.  
  14. expect "*continue*" # is there a way to only do this if the question is asked?
  15. send -- "yes\r"" # this will be the answer if the above question is asked
  16.  
  17. expect "*?ssword:*"
  18. send -- "$oldpassword\r"
  19. send -- "$cmd\r"
  20. expect "*?ssword:*"
  21. send -- "$newpassword\r"
  22. expect "*?ssword:*"
  23. send -- "$newpassword\r"
  24.  
  25. send -- "exit\r"
  26. send -- "\r"
  27.  
  28. expect eof;
  29. }