-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-running.exp
executable file
·147 lines (119 loc) · 3.42 KB
/
backup-running.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/expect
# copyright.c.2021.nic@boet.cc
log_user 0
set timeout 20
set debug 0
set trace 0
set path [file dirname [file normalize [info script]]]
source $path/inc/config.tcl
source $path/inc/common-proc.exp
if { ( [llength $argv] != 2 ) } {
puts "A10: show running and aflex configurations\n"
puts "Usage: $argv0 <hostname> <saved-config-file>"
exit 64
}
set hostname [lindex $argv 0]
set output [lindex $argv 1]
file delete $output
set prompt "$hostname-*"
#ping host, proc will exit
if { [myalive $hostname] } {
if {$debug} { puts "## icmp reachable" }
}
#spawn ssh
source $path/inc/ssh-init.exp
#############################################
#
# detect partitions - append the default "shared"
#
#show partition
#Total Number of active partitions: 2
#Total partitions allowed: 127
#Partition Name Id App Type Admin Count
#---------------------------------------------
#ssli_in 1 - 0
#ssli_out 2 - 0
##
send "show partition\r"
#buffer was not retruning expected output while using the myexec function.
expect "$prompt#"
set lines [split $expect_out(buffer) "\n"]
set partition "shared"
foreach l $lines {
if { $trace } { puts "line:$l" }
#set a mark point for the dashes
if { [info exists marked] } {
#exit if we are detect cli prompt
if { [regexp "^$hostname.*" $l] } {
break
}
set result [lindex [split $l] 0]
lappend partition $result
}
#once this section is found the partition names should be present
if {[regexp {^----} $l]} {
set marked 1
}
}
#loop each part
foreach p $partition {
#switch into the selected partition
send "active-partition $p\r"
myexpect "$prompt#"
log_file $output
send "show running-config\r"
## the running config dumps strings which match our myexec error handling.
expect "$prompt#"
log_file
#
# loop aflex scripts
#
##show aflex
#Total aFlex number: 2
#Max aFlex file size: 32K
#Name Syntax Virtual port
#------------------------------------------------------------
#foo Check Bind
#bar Check No
##
send "show aflex\r"
expect "$prompt#"
set lines [split $expect_out(buffer) "\n"]
#clear the marked tracker
if { [info exists marked] } {
unset marked
}
foreach l $lines {
if { $trace } { puts "line:$l" }
#set a mark point for the dashes
if { [info exists marked] } {
#exit if we are detect cli prompt
if { [regexp "^$hostname.*" $l] } {
break
}
set aflex [lindex [split $l] 0]
log_file $output
send "show aflex $aflex\r"
expect {
timeout {
send_user "\n## Timeout occured. Did not get the expected prompt!\n"
exit 1
}
"No such aFleX." {
send_user "\n## AFLEX detection failed.\n"
exit 1
}
"$prompt#"
}
log_file
}
#once this section is found the aflex script names should be present
if {[regexp {^----} $l]} {
set marked 1
}
}
}
#############################################
# logoff
source $path/inc/ssh-close.exp
exit 0