Posted to tcl by schelte at Sat Aug 25 20:44:32 GMT 2012view raw

  1. #!/usr/bin/expect
  2.  
  3. set file iplist.txt
  4. set cmd "ssh-copy-id -i /home/karthick/.ssh/karthick.pub"
  5. set user root
  6. set password Password123
  7.  
  8. set f [open iplist.txt]
  9. set hostlist [split [read $f] \n]
  10. close $f
  11.  
  12. foreach host $hostlist {
  13. if {$host eq ""} continue
  14.  
  15. spawn {*}$cmd $user@$host
  16. expect {
  17. -timeout 5
  18. -ex "Are you sure you want to continue connecting (yes/no)? " {
  19. send -- "yes\r"
  20. exp_continue
  21. }
  22. -ex "assword: " {
  23. send "$password\r"
  24. exp_continue
  25. }
  26. -ex "Permission denied" {
  27. puts stdout "Permission denied for $user on following server $host"
  28. set f [open login_issue.log a]
  29. puts $f "Permission denied for $user on the server $host"
  30. close $f
  31. exp_continue
  32. }
  33. timeout {
  34. set f [open unreachable.log a]
  35. puts $f "Access to server $host timed out"
  36. close $f
  37. close
  38. exp_continue
  39. }
  40. eof {}
  41. }
  42. }