summaryrefslogtreecommitdiffstats
path: root/util/cisco-reload.exp
blob: 095a3b26cf9f22c4878f8da9a2e561ee8d2f2126 (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
##
## Copyright (C) 1997-2001 by Henry Kilmer.
## All rights reserved.
##
## This software may be freely copied, modified and redistributed without
## fee for non-commerical purposes provided that this copyright notice is
## preserved intact on all copies and modified copies.
##
## There is no warranty or other guarantee of fitness of this software.
## It is provided solely "as is". The author(s) disclaim(s) all
## responsibility and liability with respect to this software's usage
## or its effect upon hardware, computer systems, other software, or
## anything else.
#
# this expect snipit 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
#
# eg 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
#
#
# 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#
##