-
Notifications
You must be signed in to change notification settings - Fork 0
/
cisco_show.exp
executable file
·85 lines (66 loc) · 1.17 KB
/
cisco_show.exp
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
#!/usr/bin/expect -f
## ekartso
if { "$argc" != 5 } {
send_user "Usage: $argv0 Username Passwd devIP hostname\n"
send_user " Ex: $argv0 efterpi kodikalaki 1.1.1.1 bras-mar3\n"
exit 1
}
set timeout 180
#username
set arg1 [lindex $argv 0]
#password
set arg2 [lindex $argv 1]
#deviceIP
set arg3 [lindex $argv 2]
#hostname
set arg4 [lindex $argv 3]
#command
set arg5 [lindex $argv 4]
#puts $arg4
if { [catch {
spawn -noecho telnet "$arg3"
}] } {
puts "ERROR: Cannot open telnet connection"
exit
}
if { [catch {
expect {
"name:" {
send "$arg1\n"}
timeout {
puts "ERROR: Timeout waiting for prompt: username"
exit
}
}
expect {
"word:" {
send "$arg2\n"}
timeout {
puts "ERROR: Timeout waiting for prompt: password"
exit
}
}
}] } {
puts "ERROR: Couldn't login to remote host"
exit
}
if { [catch {
expect {
"\#" {
send "terminal length 0\n";
}
}
expect {
"\#" {
send "$arg5\n";
}
}
expect {
"\#" {
send "exit\n"
}
}
}] } {
puts "ERROR: Disconnected from remote host"
exit
}