-
Notifications
You must be signed in to change notification settings - Fork 5
/
cs
executable file
·65 lines (47 loc) · 1.49 KB
/
cs
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
#!/usr/bin/expect -f
#cs: expect script to automate connection to cisco routers and switches with enable privileges.
#Usage: cs nick_router_name
#It uses expect, and according the config file defined at $HOME/.ciscorouters, permit both telnet and ssh connections.
#it could be executed with the "con" script file or just alone, depending if you want to keep thesession on the current terminal or on a new independent terminal either.
#Jose Antonio Montes 2011
set timeout 10
set server [lindex $argv 0]
set filename [open "~/.ciscorouters" r]
set routers_list [split [read $filename] "\n"]
close $filename
foreach router $routers_list {
if { $server == [lindex $router 0] } {
set IP [lindex $router 2]
set user [lindex $router 3]
set password [lindex $router 4]
set enpassword [lindex $router 5]
set isssh [lindex $router 6]
if { ${isssh} == "ssh" } {
spawn ssh ${user}@${IP}
expect {
"yes/no" {
send "yes\r"
exp_continue
}
"assword: " { send "$password\r" }
}
expect ">"
send "en\r"
expect "assword: "
send "$enpassword\r"
interact
exit
} else {
spawn telnet $IP
expect "Username: "
send "$user\r"
expect "Password: "
send "$password\ren\r"
expect "Password: "
send "$enpassword\r"
interact
exit
}
}
}
send_user "The $server doesn\'t exist into the router list\n"