-
Notifications
You must be signed in to change notification settings - Fork 13
/
cisco
executable file
·97 lines (91 loc) · 1.96 KB
/
cisco
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env expect
# cisco -- connect to one of the "Dunelab" Cisco1760 routers
# vim: ft=tcl
set host ""
set console 0
set enable 1
set monitor 0
set datadump 0
set backup 0
set config 0
set command ""
set cmdexit 0
foreach arg $argv {
if {$command == ""} {
switch -glob $arg {
-C { set console 1 }
-b { set backup 1 }
-c { set config 1 }
-d { set datadump 1 }
-m { set monitor 1 }
-u { set enable 0 }
-* { puts stderr "unknown option $arg"; exit 1 }
+* { set command [string trim $arg "+"]; set cmdexit 0 }
/* { set command [string trim $arg "/"]; set cmdexit 1 }
* { set host $arg }
}
} else {
switch -glob $arg {
+* { set command "$command\n[string trim $arg "+"]" }
/* { set command "$command\n[string trim $arg "/"]" }
* { set command "$command $arg" }
}
}
}
if {$backup} {
set datadump 1
set enable 1
set monitor 0
}
if {$command != ""} {
# Won't be able to interact
set datadump 1
}
if {$host == ""} {
puts stderr "host not specified"
exit 1
}
if {[regexp "^(top|mid|btm)$" $host]} {
set host "cisco-$host.sym"
}
if {$console} {
system "rcons [lindex [split $host .] 0]"
exit
}
set ::env(TERM) "xterm"
set consolepass "cisco"
set enablepass [exec getnetrc -df %p cisco enable]
puts stderr "\033\]0;telnet $host\033\\"
puts stderr "\033k[regsub "\\.sym$" $host ""]\033\\"
spawn telnet $host
expect "Password:" { send "$consolepass\r" }
set prompt ">"
if {$enable} {
expect $prompt { send "enable\r" }
expect "Password:" { send "$enablepass\r" }
set prompt "#"
}
if {$datadump} {
expect $prompt { send "terminal length 0\r" }
}
if {$backup} {
expect $prompt { send "show run\r" }
expect $prompt { send "logout\r" }
exit
}
if {$monitor} {
expect $prompt { send "terminal monitor\r" }
}
if {$config} {
expect $prompt { send "config terminal\r" }
}
if {$command != ""} {
foreach line [split $command "\n"] {
expect $prompt { send "$line\r" }
}
if {$cmdexit} {
expect $prompt { send "logout\r" }
exit
}
}
interact