Posted to tcl by schelte at Sat Aug 25 20:07:33 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. -ex "Are you sure you want to continue connecting (yes/no)? " {
  18. send -- "yes\r"
  19. exp_continue
  20. }
  21. -ex "assword: " {
  22. send "$password\r"
  23. exp_continue
  24. }
  25. -ex "Permission denied" {
  26. puts stdout "Permission denied for $user on following server $host"
  27. set f [open login_issue.log a]
  28. puts $f "Permission denied for $user on the server $host"
  29. close $f
  30. }
  31. eof {}
  32. }
  33. }