Posted to tcl by schelte at Sat Aug 25 20:52:50 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 timeout 5
  9.  
  10. set f [open iplist.txt]
  11. set hostlist [split [read $f] \n]
  12. close $f
  13.  
  14. foreach host $hostlist {
  15. if {$host eq ""} continue
  16.  
  17. spawn {*}$cmd $user@$host
  18. expect {
  19. -ex "Are you sure you want to continue connecting (yes/no)? " {
  20. send -- "yes\r"
  21. exp_continue
  22. }
  23. -ex "assword: " {
  24. send "$password\r"
  25. exp_continue
  26. }
  27. -ex "Permission denied" {
  28. puts stdout "Permission denied for $user on following server $host"
  29. set f [open login_issue.log a]
  30. puts $f "Permission denied for $user on the server $host"
  31. close $f
  32. exp_continue
  33. }
  34. timeout {
  35. set f [open unreachable.log a]
  36. puts $f "Access to server $host timed out"
  37. close $f
  38. close
  39. wait
  40. }
  41. eof {}
  42. }
  43. }