From: Heinrich Piard Date: 2008-07-24T03:41:40+09:00 Subject: Cisco tftp upload via snmpset Hi all, whoever is interested in it. #!/usr/bin/ruby #Version 0.1 Heinrich Piard - basic version of snmpset-copy-running-config-to-tftp.rb require 'yaml' require 'snmp' require 'socket' #require 'daemons' #require 'action_mailer' require 'csv' include Socket::Constants #include Daemonize # Cisco OIDs (variables) #The ConfigCopyProtocol is set to TFTP oid_setTFTP = "1.3.6.1.4.1.9.9.96.1.1.1.1.2.111 i 1" #Set the SourceFileType to running-config oid_setRUNNINGCONFIG = "1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4" #Set the DestinationFileType to networkfile oid_setDSTFILENETWORK = "1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 1" #Sets the ServerAddress to the IP address of the TFTP server 1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a oid_setIPADDRTFTPSERVER = "1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a" #Sets the CopyFilename to your desired file name 1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s oid_setDSTFILENAME = "1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s" #Sets the CopyStatus to active which starts the copy process 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1 oid_setSTARTPROCESS = "1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1" #idcnetwatch1.bxc.is-teledata.com (TFTP server) tftpserver = '172.29.0.254' #hostlist including all switches hostlist = '/homes/network-monitoring/snmpset-copy-running-config-to-tftp.conf' #snmp RO rocommunity = 'public' #snmp RW rwcommunity = 'secret' #start logic #check if configfile is available if ((File.exist?(hostlist)) && (File.readable?(hostlist))) host = CSV.readlines(hostlist) else puts 'Cannot locate configuration file! Please check!' exit end host.each do |ip| system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setTFTP}") system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setRUNNINGCONFIG}" ) system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setDSTFILENETWORK}" ) system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setIPADDRTFTPSERVER} #{tftpserver}" ) system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setDSTFILENAME} #{ip}" ) system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setSTARTPROCESS}" ) end -- Posted via http://www.ruby-forum.com/.