diff options
Diffstat (limited to 'share/cisco-reload.exp')
-rw-r--r-- | share/cisco-reload.exp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/share/cisco-reload.exp b/share/cisco-reload.exp new file mode 100644 index 0000000..25880c1 --- /dev/null +++ b/share/cisco-reload.exp @@ -0,0 +1,147 @@ +## +## $Id: cisco-reload.exp,v 1.9 2004/01/11 03:43:50 heas Exp $ +## +## Copyright (C) 1997-2004 by Terrapin Communications, Inc. +## All rights reserved. +## +## This software may be freely copied, modified and redistributed +## without fee for non-commerical purposes provided that this license +## remains intact and unmodified with any RANCID distribution. +## +## 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. +## +## Except where noted otherwise, rancid was written by and is maintained by +## Henry Kilmer, John Heasley, Andrew Partan, Pete Whiting, and Austin Schutz. +## +# +# 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 +# +# 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 +# +# +# 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# +## |