cisco_static.sh 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "no ip proxy-arp\r"
  39. expect "*(config-if)#"
  40. send "no ip redirects\r"
  41. expect "*(config-if)#"
  42. send "no ip unreachable\r"
  43. expect "*(config-if)#"
  44. send "exit\r"
  45. expect "*(config)#"
  46. send "ip route $addr 255.255.255.255 vlan$vlan\r"
  47. expect "*(config)#"
  48. send "end\r"
  49. expect "*#"
  50. send "write\r"
  51. expect "*#"
  52. send "exit\r"