cisco.sh 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/local/bin/expect -f
  2. set timeout 4
  3. set username [lindex $argv 0]
  4. set password [lindex $argv 1]
  5. set vlan [lindex $argv 2]
  6. set int [lindex $argv 3]
  7. set addr [lindex $argv 4]
  8. set host [lindex $argv 5]
  9. spawn ssh $username@$host
  10. expect {
  11. "(yes/no)?*" {
  12. send "yes\r"
  13. }
  14. }
  15. expect "Password:*"
  16. send "$password\r"
  17. expect {
  18. "*>" {
  19. send "enable\r"
  20. expect "Password: *"
  21. send "$password\r"
  22. expect "*#"
  23. send "configure terminal\r"
  24. }
  25. "*#" {
  26. send "configure terminal\r"
  27. }
  28. }
  29. expect "*(config)#"
  30. send "vlan $vlan\r"
  31. expect "*(config-vlan)"
  32. send "exit\r"
  33. expect "*(config)#"
  34. send "interface vlan $vlan\r"
  35. expect "*(config-if)#"
  36. send "ip unnumbered $int\r"
  37. expect "*(config-if)#"
  38. send "ip helper-address $addr\r"
  39. expect "*(config-if)#"
  40. send "no ip proxy-arp\r"
  41. expect "*(config-if)#"
  42. send "no ip redirects\r"
  43. expect "*(config-if)#"
  44. send "no ip unreachable\r"
  45. expect "*(config-if)#"
  46. send "end\r"
  47. expect "*#"
  48. send "write\r"
  49. expect "*#"
  50. send "exit\r"