SecureCRT Scripts

From: Todd.Osterberg@compucom.com
Date: Sat Apr 29 2006 - 20:33:15 GMT-3


I've written a couple of scripts for SecureCRTv5 that are for the fast
setup and archiving of lab hw configs. The scripts are focused on the
internetworkexpert labs but could be easily modified to fit other
workbooks.

The first script is called the flipper. Its purpose is to copy a
baseline config into the startup config and reboot the device. The
second script is called the saver. It is used to copy the running
config to flash. These scripts have saved me a fair amount of time in
that it now takes me 2-3 minutes to setup my rack for a lab - error
free.

Save each of them to a file. To use them, launch SecureCRT and then
choose script/run and you're off to the races.

Again, the scripts are provided without any support or guarantee.
Please don't email me directly for support questions. In all honesty,
in prepping for my lab, I don't have time to answer support questions.
YMMV.

Todd

1st Script: The flipper

----------------------------------------------------------------

#$language = "VBScript"

#$interface = "1.0"

Sub main

Dim logfile

Dim accesserver

' CCIE lab initial configuration rotator - a.k.a flipper

'

'(c) 2006 Todd Allen Osterberg

'

' Use at your own risk, there is no guarantee this will work on your
hardware.

'

' I'm not in the free-software support business.

'

' The script has several dependencies, first of which is that you have
pre-loaded

' config scripts to the local file system and the files must follow this
naming convention:

'

' labnumber.Rack1RX for routers, where X is the device number

' labnumber.Rack1SWx for switches, where is is the device number

'

'The script also assumes that R1 is on the first line and all other

'devices are on subsequent lines.

'

'Your devices must follow the IE standard naming convention of Rack1Rx
or Rack1SWx.

'

'The script won't execute if you have an existing connection to any of
the devices.

'

'It is not perfect, but it saves a lot of time.

'

 ' turn on synchronous mode so we don't miss any data

  crt.Screen.Synchronous = True

 ' prompt the user for a password

msgbox "This script will ERASE the running configuraiton of all routers.
Cancel Now or else..."

labnumber = "lab" & crt.Dialog.Prompt("Lab #", "Enter the Lab #", "",
false)

'change this variable to the ip addr of your access server

accessserver = "10.1.4.75"

for x = 1 to 8

 hostname = "Rack1R"&x&"#"

 newcfg = labnumber & "." & "Rack1R" & x

 if x > 6 then hostname ="Rack1SW" & (x-6) & "#"

 if x > 6 then newcfg = labnumber & "." & "Rack1SW" & (x-6)

 crt.Session.Connect "/TELNET " & accessserver & " 200" & x

 crt.Screen.Send VbCr & VbCr & VbCr & VbCr & VbCr & VbCr

 crt.Screen.WaitForString "Rack1"

 Crt.Screen.Send "enable" & VbCr

 crt.Screen.WaitForString "Rack1"

 Crt.Screen.Send "term len 0" & VbCr

 Crt.Screen.WaitForString hostname

 src="flash"

 ' you may ned to commend out this next line and/or mod it if any of
your hardware

 ' uses non-flash filesystems. This line was added to support a 7200
with ATA-flash cards

 '

 if hostname ="Rack1R5#" then src="disk0"

 Crt.Screen.Send "copy "& src & ":"& newcfg & " start" & VbCr

 Crt.Screen.WaitForString "config]"

 Crt.Screen.Send VbCr

 Crt.Screen.WaitForString hostname

 if left(hostname,7) = "Rack1SW" then

  crt.Screen.Send "del vlan.dat" & VbCr

  crt.Screen.WaitForString ".dat]?"

  crt.Screen.Send "vlan.dat" & VbCr

  crt.Screen.WaitForString "[confirm]"

  crt.Screen.Send "y" & VbCr

 end if

 crt.Screen.Send "reload" & VbCr

 crt.Screen.WaitForString "[confirm]"

 crt.Screen.Send VbCr

 Crt.Session.Disconnect

next

End Sub

----------------------------------------------------------------

2nd script: The saver

#$language = "VBScript"

#$interface = "1.0"

Sub main

Dim logfile

Dim accessserver

' CCIE lab config saver

'

'(c) 2006 Todd Allen Osterberg

'

' Use at your own risk, there is no guarantee this will work on your
hardware

'

' The script has several dependencies, first of which is that you have
pre-loaded

' config scripts to the local file system and the files must follow this
naming convention:

'

' labnumber.Rack1RX for routers, where X is the device number

' labnumber.Rack1SWx for switches, where is is the device number

'

'The script also assumes that R1 is on the first line and all other

'devices are on subsequent lines.

'

'Your devices must follow the IE standard naming convention of Rack1Rx
or Rack1SWx.

'

'The script won't execute if you have an existing connection to any of
the devices.

'

'It is not perfect, but it saves a lot of time.

'

'change this variable to the ip addr of your access server

accessserver = "10.1.4.75"

 ' turn on synchronous mode so we don't miss any data

  crt.Screen.Synchronous = True

 ' prompt the user for a password

msgbox "This script will SAVE the running configuraiton of all routers.
Cancel Now or else..."

labnumber = "lab" & crt.Dialog.Prompt("Lab #", "Enter the Lab #", "",
false)

reload = "lab" & crt.Dialog.Prompt("reload after cfg?", "enter yes to
have devices reloaded", "", false)

for x = 1 to 8

 hostname = "Rack1R"&x&"#"

 newcfg = labnumber & "." & "Rack1R" & x

 if x > 6 then hostname ="Rack1SW" & (x-6) & "#"

 if x > 6 then newcfg = labnumber & "." & "Rack1SW" & (x-6)

 crt.Session.Connect "/TELNET " & accessserver & " 200" & x

 crt.Screen.Send VbCr & VbCr & VbCr & VbCr & VbCr & VbCr

 crt.Screen.WaitForString "Rack1"

 Crt.Screen.Send "enable" & VbCr

 crt.Screen.WaitForString "Rack1"

 Crt.Screen.Send "term len 0" & VbCr

 Crt.Screen.WaitForString hostname

 src="flash"

 ' you may ned to commend out this next line and/or mod it if any of
your hardware

 ' uses non-flash filesystems. This line was added to support a 7200
with ATA-flash cards

 '

 if hostname ="Rack1R5#" then src="disk0"

 Crt.Screen.Send "copy run "& src & ":" & newcfg &"-end.cfg" & VbCr

 Crt.Screen.WaitForString "end.cfg]"

 Crt.Screen.Send VbCr

 if hostname <> "Rack1R5#" then Crt.Screen.WaitForString "[confirm]"

 if hostname <> "Rack1R5#" then Crt.Screen.Send "n" & VbCr

 if hostname <> "Rack1R5#" then Crt.Screen.WaitForString hostname

 'handle vlan.dat

 if left(hostname,7) = "Rack1SW" then

   Crt.Screen.Send "copy run "& src & ":" & newcfg &"-vlan.dat" & VbCr

   Crt.Screen.WaitForString ".dat]"

   Crt.Screen.Send VbCr

 end if

if reload = "yes" then

 crt.Screen.Send "reload" & VbCr

 crt.Screen.WaitForString "[confirm]"

 crt.Screen.Send VbCr

end if

Crt.Session.Disconnect

next

End Sub



This archive was generated by hypermail 2.1.4 : Mon May 01 2006 - 11:41:59 GMT-3