-
Notifications
You must be signed in to change notification settings - Fork 29
/
asa.exp
67 lines (57 loc) · 1.18 KB
/
asa.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
#!/usr/bin/expect -f
# Set variables
set hostip [lindex $argv 0]
set hostname [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
set enablepassword [lindex $argv 4]
set logfile [lindex $argv 5]
spawn ssh -o StrictHostKeyChecking=no $username\@$hostip
expect {
timeout { send_user "\nTimeout Exceeded - Check Host\n"; exit 1 }
eof { send_user "\nSSH Connection To $hostname Failed\n"; exit 1 }
"*#" {}
"*assword:" {
send "$password\n"
}
}
expect {
default { send_user "\nEnable Mode Failed - Check Password\n"; exit 1 }
"*#" {}
"*>" {
send "enable\r"
expect "*assword"
send "$enablepassword\r"
expect "*#"
}
}
send "terminal pager 0\r"
expect "*#"
log_user 0
log_file -noappend -a ${logfile}.groups
send "sh run | inc access-group\n"
expect {
"$hostname/*#" {}
"$hostname#" {}
}
log_file
send_user "\n${hostname} ACL groups saved\n"
set timeout 3600
log_file -noappend -a ${logfile}.conf
send "sh run \r"
expect {
"$hostname/*#" {}
"$hostname#" {}
}
log_file
send_user "\n${hostname} config saved\n"
log_file -noappend -a ${logfile}.out
send "sh access-list\r"
expect {
"$hostname/*#" {}
"$hostname#" {}
}
log_file
send_user "\n${hostname} ACLs saved\n"
send "exit\r"
exit 0