-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_cisco_ios.exp
More file actions
79 lines (68 loc) · 1.3 KB
/
backup_cisco_ios.exp
File metadata and controls
79 lines (68 loc) · 1.3 KB
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
#!/usr/bin/expect
set timeout 15
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set en_password [lindex $argv 3]
set tftp [lindex $argv 4]
set file [lindex $argv 5]
#Open the SSH session
spawn ssh -o "StrictHostKeyChecking=no" -l $username $host
sleep 2
#Catch the password prompt and send supplied password
expect {
"word:" {send "$password\r"}
default {exit 1}
}
sleep 1
# Enter enable mode
expect {
">" {send "enable\r"}
default {exit 1}
}
sleep 1
#Catch the password prompt and send supplied password
expect {
"word:" {send "$en_password\r"}
default {exit 1}
}
sleep 1
#Catch the enabled prompt and issue the command to backup running configuration
expect {
"#" {send "copy running-config tftp:\r"}
default {exit 1}
}
sleep 1
#Expect the two confirmation questions and answer
expect {
"?" {send "$tftp\r"}
}
sleep 1
expect {
"?" {send "$file.running\r"}
}
#Wait long enough for file transfer.
sleep 5
# Test xfer worked otherwise exit
expect {
"copied" { }
default {exit 1}
}
# Backup startup config
expect {
"#" {send "copy startup-config tftp:\r"}
}
sleep 1
#Expect the two confirmation questions and answer
expect {
"?" {send "$tftp\r"}
}
sleep 1
expect {
"?" {send "$file.startup\r"}
}
# Test xfer worked otherwise exit
expect {
"copied" { }
default {exit 1}
}