summaryrefslogtreecommitdiffstats
path: root/share/cisco-reload.exp
blob: 45fbad0abb5e5a5fbae3c07b4b4bf503e6835b3d (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
##
## $Id$
##
## Copyright (c) 1997-2007 by Terrapin Communications, Inc.
## All rights reserved.
##
## This code is derived from software contributed to and maintained by
## Terrapin Communications, Inc. by Henry Kilmer, John Heasley, Andrew Partan,
## Pete Whiting, Austin Schutz, and Andrew Fort.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
## 1. Redistributions of source code must retain the above copyright
##    notice, this list of conditions and the following disclaimer.
## 2. Redistributions in binary form must reproduce the above copyright
##    notice, this list of conditions and the following disclaimer in the
##    documentation and/or other materials provided with the distribution.
## 3. All advertising materials mentioning features or use of this software
##    must display the following acknowledgement:
##        This product includes software developed by Terrapin Communications,
##        Inc. and its contributors for RANCID.
## 4. Neither the name of Terrapin Communications, Inc. nor the names of its
##    contributors may be used to endorse or promote products derived from
##    this software without specific prior written permission.
## 5. It is requested that non-binding fixes and modifications be contributed
##    back to Terrapin Communications, Inc.
##
## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC. AND CONTRIBUTORS
## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COMPANY OR CONTRIBUTORS
## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
## POSSIBILITY OF SUCH DAMAGE.
# 
#  The expect login scripts were based on Erik Sherk's gwtn, by permission.
# 
#  The original looking glass software was written by Ed Kern, provided by
#  permission and modified beyond recognition.
#
# This expect snippet is sourced by clogin (-s option) to issue a reload
# command on a cisco router.  It DOES NOT save the config if it has been
# modified.  This is an _example_ as it not guaranteed to work for all
# applications.  PLEASE test for your environment.
#
# It expects the following variables via the -E option:
#	reload_arg	='command argument' such as 'at 05:00' or 'cancel
#
# e.g. usage:
# % clogin -s cisco-reload.exp -Ereload_arg='at 01:00' router
# router
#	Reload scheduled for 01:00:00 UTC Sat Jun 23 2001 (in 7 hours and 16 minutes)
# % clogin -s cisco-reload.exp -Ereload_arg='at cancel' router
# router
#	% Ambiguous command:  "reload at cancel"
#
# % clogin -s cisco-reload.exp -Ereload_arg='cancel' router
# router
#	SHUTDOWN ABORTED
#
# exit is called at the end, so only one router can be handled per clogin.
#
# Keep in mind that it is important to NOT polute the global variable space.
# Particularly, do not use variables used within clogin.  This may result in
# indeterministic results.  An easy way to avoid this is to use a variable
# name prefix (like 'E' or '_').
#
# Useful variables from clogin global space:
#	router		router name as provided on the cmd-line
#	prompt		cmd-line prompt as determined by clogin
#
# note: the tcl/expect parser is extremely stoopid.  Comment lines are NOT
#	completely ignored!!  So, a '{' or '}' in a comment might produce
#	unexpected results.
##
# exp_internal 1
# log_user 1

# take reload command from -Ereload_arg='at 05:00'
if ([info exists Ereload_arg]) {
	#puts "reload_arg == $Ereload_arg"
	set reloadcmd "reload $Ereload_arg"
} else {
	send_error "ERROR: -Ereload_arg= was not set on the command-line.\n"
	exit
}

#send_user "$router\n"

send "\r"
expect {
    timeout 			{ send_error "Error: did not receive prompt\n"
				  exit }
    -re "^.*$prompt"		{ send "$reloadcmd\r"
				  expect * {} }
}
# look for response
expect	{
    -re "configuration has been modified.*no.:"	{ send "no\r";
					  exp_continue }
    -re "Reload scheduled .*\r"		{ set sched $expect_out(0,string)
					  exp_continue }
    -re "SHUTDOWN ABORTED"		{ set sched $expect_out(0,string) }
    -re "Proceed with .*confirm\]"	{ send "\r" }
    -re "\n.*No reload "		{ set sched "no reload scheduled"
					  send "\r" }
    -re "% Ambig\[^\n\r]*"		{ set sched $expect_out(0,string) }
}
send "\r"
expect "$prompt"
if ([info exists sched]) {
	send_user "\t$sched\n"
}
send "quit\r"
expect {
	timeout		{ send_error "Error: timeout waiting for EOF after quit\n"}
	eof	{ exit 0 }
}

## dennis#reload in ?
## Delay before reload (mmm or hhh:mm)
##
## dennis#reload in 100:10
##
## System configuration has been modified. Save? [yes/no]: no
## Reload scheduled in 100 hours and 9 minutes
## Proceed with reload? [confirm]
## dennis#reload ca
## dennis#reload cancel
## dennis#
##
##
## ***
## *** --- SHUTDOWN ABORTED ---
## ***
##
## dennis#wr
## Building configuration...
## [OK]
## dennis#reload in 100:10
## Reload scheduled in 100 hours and 10 minutes
## Proceed with reload? [confirm]
## dennis#rel
## dennis#reload can
## dennis#reload cancel
## dennis#
##
##
## ***
## *** --- SHUTDOWN ABORTED ---
## ***
## System configuration has been modified. Save? [yes/no]: no
## Reload scheduled for 11:51:48 PST Thu Dec 10 1998 (in 299 hours and 59 minutes)
## Proceed with reload? [confirm]
## ultra#reload can
## ultra#
##
##
## ***
## *** --- SHUTDOWN ABORTED ---
## ***
## ultra# reload at 8:10 10 dec
##
## System configuration has been modified. Save? [yes/no]: no
## Reload scheduled for 08:10:00 PST Thu Dec 10 1998 (in 296 hours and 17 minutes)
## Proceed with reload? [confirm]
## ultra#
##