I don't like how Orion upgrades IOS, it wants me to specify an image and a target for that image. On my many WAN sites, I have a mixture of Cisco switch models. I want to point the script at that site and let the script figure out what image is appropriate for that switch. Using Tereterm, I created a script to do this for one switch...it prompts for an address. Using Excel, I maintain a two column CSV specifying models and desired images. Here is a snip:
WS-C2960CG-8TC-L,c2960c405ex-universalk9-mz.152-2.E6.bin
WS-C2960CPD-8TT-L,c2960c405-universalk9-mz.152-2.E6.bin
WS-C2960CX-8TC-L,c2960cx-universalk9-mz.152-4.E4.bin
WS-C2960G-24TC-L,c2960-lanbasek9-mz.122-55.SE12.bin
WS-C2960G-48TC-L,c2960-lanbasek9-mz.122-55.SE12.bin
WS-C2960G-8TC-L,c2960-lanbasek9-mz.122-55.SE12.bin
WS-C2960S-24LPS-L,c2960s-universalk9-mz.150-2.SE11.bin
The script extracts the model from the results of 'sh ver' and then reads the CSV to get the desired .bin . It works well except that 100mb switches consistently timeout using TFTP, regardless of the connection between switch and TFTP server. FTP works much better, but I haven't modified the script to use FTP.
I would like to create a job in Orion to do the same thing. For each node, I have a custom field called Site. That is populated with a number we have assigned to each remote office. I would like to simply specify the site number and have the script run against each switch on that site.
I have attached a sample Teraterm script. That one also prompts for logon credentials but I wouldn't do that in an Orion script.
; Upgrade IOS on Cisco switch
;
; Ed Bonnell
; September 2017
;
; This Teraterm script will:
; 1. prompt for switch address and credentials
; 2. query switch for model
; 3. open file containing models and images
; 4. read records from image file until a match is found
; 5. download the appropriate image file to flash
; 6. set the system boot variable
;
; This script does not reboot the switch.
;
imagelist = 'imagelist.csv'
;connect to switch
inputbox 'What is the switch address?' 'SWITCH'
switch = inputstr
switchaddr = switch
tolower test4cancel switch
strcompare test4cancel 'cancel'
if result=0 end
;
call getcreds
;
logfile = 'c:\log\'
strconcat logfile switchaddr
strconcat logfile '.log'
messagebox logfile 'Log File'
;
strconcat switch ' /ssh /2 /auth=password '
strconcat switch creds
connect switch
if result=1 goto switchnotanswering
wait '#'
logopen logfile 0 0
:openfile
fileopen fh imagelist 0 0
; set pointer to start of the file
fileseek fh 0 0
:readarecord
; read a record from file
filereadln fh record
if result goto modelnotfound
; find length of record
strlen record
recordlength = result
; find position of comma
strscan record ','
position = result
if result=0 goto problem
; extract model from record
trimlength = recordlength - position
trimlength = trimlength + 1
modelfromfile = record
;messagebox recordlength 'record length'
;messagebox trimlength 'trim length'
;messagebox modelfromfile 'model from file'
;end
strremove modelfromfile position trimlength
;check switch model
timeout = 2
sendln 'sh ver | inc WS-C'
wait modelfromfile
; if timeout
if result=0 then
goto readarecord
endif
image = record
strscan record ','
position = result
strremove image 1 position
;messagebox image "image from record'
:closefile
fileclose fh
;
; now we know the switch model
; and corresponding IOS image filename
;
; does image already exist on switch flash?
timeout=3
sendln 'show flash:'
wait image
if result=1 goto imageexists
;
copycmd = 'copy tftp://10.100.93.162/'
strconcat copycmd image
strconcat copycmd ' flash:'
verifycmd = 'verify /md5 flash:'
strconcat verifycmd image
bootcmd = 'boot system flash:'
strconcat bootcmd image
timeout = 600
sendln 'conf t'
sendln 'ip tftp blocksize 1024'
sendln 'end'
sendln copycmd
sendln ''
waitln '[OK - ' 'rror'
copyresult = result
;messagebox result "COPY Result ='
if copyresult=0 goto transfertimeout
;if copyresult=1 goto verifyfile
if copyresult=2 goto problem
:verifyfile
pause 1
sendln verifycmd
wait '#'
beep 4
:continue
sendln 'conf t'
sendln bootcmd
;messagebox bootcmd 'BOOTCMD'
sendln 'end'
sendln 'wr'
sendln 'q'
:theend
closett
end
:getcreds
inputbox 'What is your Username?' 'Username'
username = inputstr
tolower test4cancel username
strcompare test4cancel 'cancel'
if result=0 end
inputbox 'What is your password?' 'Username'
pwd = inputstr
tolower test4cancel pwd
strcompare test4cancel 'cancel'
if result=0 end
creds = ' /user='
strconcat creds username
strconcat creds ' /passwd='
strconcat creds pwd
;messagebox 'finished get creds' 'creds'
return
:switchnotanswering
messagebox 'Cannot connect to switch' switchaddr
closett
end
:problem
messagebox 'There is a problem with the ImageList file!' 'ABORTED!'
closett
end
:modelnotfound
messagebox 'Model not in ImageList file' 'NOT FOUND'
closett
end
:somethingiswrong
messagebox 'Something is wrong parsing model from sh ver' 'No model in sh ver'
closett
end
:imageexists
messagebox 'Image is already on switch flash' 'ALREADY THERE'
closett
end
:transfertimeout
messagebox 'Timeout during file transfer' 'TIMEOUT'
closett
end