Cisco Flash for 1900 Series

From Bubba.org

Jump to: navigation, search

Cisco Flash is a perl script that automates the flash upgrade procedure on many early model Cisco switches. Requires a tftp server and perl SNMP module, and some old Cisco gear.

#!/usr/bin/perl
#
# This script will automate the flash upgrade procedure on
# cisco 19xx, 28xx series switches.  This script will update 
# all information on the switch that is needed to perform 
# the upgrade (tftp server ip, image name), and then reload
# the switch.  WARNING:  This script will initiate a tftp
# upgrade which will cause your switch to reboot.
#
# This has been tested on the following switches:
# Cisco 1900, 2820. This will possibly work on all switches
# from 1200 to 2820 but I do not have access to these devices 
# to test them.  It is doubtful that this will work on any 
# devices greater than 2820.   If you test this on any other
# switches, please let me know about your success/failure.
# 
# OID's for Cisco Switches 
# enterprises.437.1.1.3.5.5.0   # ip address of tftp server (ipaddr ipaddress)
# enterprises.437.1.1.3.5.6.0   # tftp file (octstr filename)
# enterprises.437.1.1.3.5.7.0   # tell's it to go ahead and flash (integer 1/2)
# enterprises.437.1.1.3.5.9.0   # tell switch to accept tftp (integer 1/2)
#
# Input File Format
# <switch name or ip>:<rw string>:<tftp server ip>:<image name>
#
# [email protected]
# v1 - 5/16/01 - Initial release
# v2 - 6/9/01  - Bug in reading image file off of the input file.
#                I still haven't figured out whether I'm causing it when
#                I'm generating my input files or whether the script is
#                generating it.  If need be, uncomment the line that looks
#                like this:       chop($im);
 
 
use SNMP;
 
$ARGC=@ARGV;
 
if ($ARGC ne 1) {
	print "Usage: $0 <input filename>\n\n";
	print "Input File Format:\n";
	print "<switch name or ip>:<rw string>:";
	print "<tftp server ip>:<image name>\n";
	exit;
}
 
open(IN, "$ARGV[0]") or die "Cannot open $ARGV[0]\n";
while(<IN>) {
	chomp;
	($n,$rw,$tftp,$im)=split(/\:/);
	print "$n\n\t";
	#chop($im);
	&write_var("437.1.1.3.5.6.0","OCTETSTR",$im,"Image",$n,$rw);
	&write_var("437.1.1.3.5.5.0","IPADDR",$tftp,"TFTP Server",$n,$rw);
	&write_var("437.1.1.3.5.9.0","INTEGER","1","TFTP Accept",$n,$rw);
	&write_var("437.1.1.3.5.7.0","INTEGER","1","TFTP Initiate",$n,$rw);
	print "\n";
}
 
# write variables to the switch
# (OID, OID Type, Value, Description, Hostname, RW String)
sub write_var {
	my($oid,$type,$val,$desc,$name,$rw)=@_;
	$sess = new SNMP::Session(DestHost => $name,
				  Community => $rw);
	$vars = new SNMP::Varbind;
	$vars->[0]='enterprises';
	$vars->[1]=$oid;
	$vars->[2]=$val;
	$vars->[3]=$type;
	$sess->set($vars);
	print "$desc: ";
	if (0 != $sess->{ErrorNum}) {
		# write was unsuccessful
		# 1) is the switch pingable?
		# 2) do you have the correct rw string?
		# 3) is this a 19xx or 2820?
		print "$sess->{ErrorStr}\n\t";
	} else {
		# write was successful
		# weather the switch actually took the image is
		# not known.  Your tftp server should be able
		# to provide this information.
		print "OK\n\t";
	}
}