Guest User

Untitled

a guest
Apr 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/usr/bin/expect -f
  2. #set variables
  3. set hostname ...
  4. set username..
  5. set ip ...
  6. foreach hostname [array names interface] {
  7. set timeout 10
  8. match_max 500000
  9. # Log results
  10. log_file -a ~/results.log
  11.  
  12. send_user "n"
  13. send_user ">>>> Working on $hostname @ [exec date]<<<< n"
  14. send_user "n"
  15. #ssh
  16. spawn ssh -2 -o strictHostKeyChecking=no $username@$ipaddress
  17. expect "username:"
  18. send "$usernamer"
  19. expect "#"
  20. expect "password:"
  21. send "$passwordr"
  22. expect -re $prompt
  23. #enable configure mode
  24. send "conf tn"
  25. expect "(config#)"
  26. #vlan trunking mode
  27. send "$interface($hostname)n"
  28. expect "(config-if-range)#"
  29. send "switchport access vlan 9n"
  30. expect "(config-if-range)#"
  31. send "switchport trunk encapsulation dot1qn"
  32. expect "(config-if-range)#"
  33. send "switchport mode trunkn"
  34. expect "(config-if-range)#"
  35. send "switchport trunk allowed vlan 7n"
  36. expect "(config-if-range)#"
  37. send "endn"
  38. expect "#"
  39. send "write memn"
  40. expect "#"
  41.  
  42. send "terminal length 0r"
  43. expect "#"
  44. send "show running-configr"
  45. expect "#"
  46. }
  47. set output $expect_out(buffer)
  48. puts "$output"
  49. #Here dont working
  50. puts -nonewline "Are you sure configuration is finished?(Y/n):"
  51. set res [read stdin 1]
  52. if { $res != "y" && $res != "Y" } {send_user -- "write memn"}
  53. }
  54. else { exp_continue
  55.  
  56. }
  57.  
  58. expect eof
  59. exit
Add Comment
Please, Sign In to add comment