This is a small expect script that accepts unknown hosts as arguments and passes 'yes' to them, so they are automatically accepted in ~/.ssh/known_hosts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
586B

  1. #!/usr/bin/expect -f
  2. # This is a small script that accept unknown hosts as arguments and passes
  3. # 'yes' to them, so they are automatically accepted in ~/.ssh/known_hosts
  4. #
  5. # Based on:
  6. # http://stackoverflow.com/questions/30206430/parsing-command-line-using-argc-and-argv-in-expect
  7. #
  8. # Usage: ./accept-yes.exp server1 server2 ...
  9. set count 0
  10. if { $argc ==0 } {
  11. puts "No arguments passed!\n"
  12. exit 1
  13. }
  14. foreach arg $argv {
  15. spawn ssh -l ubuntu $arg
  16. expect "(yes/no)?"
  17. send "yes\r"
  18. send "exit\r"
  19. incr count
  20. }
  21. puts "\n$count nodes have been accepted as known.\n"