cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
675
Views
0
Helpful
2
Replies

scripting backups of SG3xx and SG5xx switches

Brendan Kearney
Level 1
Level 1

i am trying to write a script to automate the backup of the startup or running configs to a tftp server, but keep running into issues with the snmpset command.  it does not seem to like the STRING TYPE i am setting.  at first it complains about the "a" or IpAddress TYPE, so i remove those lines.  then it complains about the "i" or INTEGER TYPE.  any ideas what i am doing wrong?

 

#!/bin/bash

host=$1
string='snmpWriteString'
filename=$host\_$(date +%b.%d.%Y)_startup_config.txt
mib=/usr/share/snmp/mibs/CISCOSBcopy.mib

rlCopyRowStatus=4  #create and go
rlCopySourceLocation=1  #local
rlCopySourceIpAddress=0.0.0.0
rlCopySourceUnitNumber=1  #unit number in stack
rlCopySourceFileName=""  #blank
rlCopySourceFileType=3  #startup config, 2 for running config
rlCopyDestinationLocation=3  #tftp
rlCopyDestinationIpAddress=192.168.88.1  #tftp server ip
rlCopyDestinationUnitNumber=1  #unit number in stack
rlCopyDestinationFileName="$filename"

snmpset -v2c -c $string -m /usr/share/snmp/mibs/CISCOSBcopy.mib $host \
        rlCopyRowStatus.0 i $rlCopyRowStatus \
        rlCopySourceLocation.0 i $rlCopySourceLocation \
        rlCopySourceIpAddress.0 a $rlCopySourceIpAddress \
        rlCopySourceUnitNumber.0 i $rlCopySourceUnitNumber \
        rlCopySourceFileName.0 s $rlCopySourceFileName \
        rlCopySourceFileType.0 i $rlCopySourceFileType \
        rlCopyDestinationLocation.0 i $rlCopyDestinationLocation \
        rlCopyDestinationIpAddress.0 a $rlCopyDestinationIpAddress \
        rlCopyDestinationUnitNumber.0 i $rlCopyDestinationUnitNumber \
        rlCopyDestinationFileName.0 s $rlCopyDestinationFileName
2 Replies 2

Michal Bruncko
Level 4
Level 4

Hello

place row

rlCopyRowStatus.0 i $rlCopyRowStatus

at the end of whole command, i.e.:

snmpset -v2c -c $string -m /usr/share/snmp/mibs/CISCOSBcopy.mib $host \
        rlCopySourceLocation.0 i $rlCopySourceLocation \
        rlCopySourceIpAddress.0 a $rlCopySourceIpAddress \
        rlCopySourceUnitNumber.0 i $rlCopySourceUnitNumber \
        rlCopySourceFileName.0 s $rlCopySourceFileName \
        rlCopySourceFileType.0 i $rlCopySourceFileType \
        rlCopyDestinationLocation.0 i $rlCopyDestinationLocation \
        rlCopyDestinationIpAddress.0 a $rlCopyDestinationIpAddress \
        rlCopyDestinationUnitNumber.0 i $rlCopyDestinationUnitNumber \
        rlCopyDestinationFileName.0 s $rlCopyDestinationFileName \
        rlCopyRowStatus.0 i $rlCopyRowStatus

 

My understanding of error "Reason: wrongValue (The set value is illegal or unsupported in some way)" using original command is that value "rlCopyRowStatus.0" could be filled with "4" only in case that all other fields are filled accordingly. For me filling "rlCopyRowStatus.0" with "4" is the GO decision to perform copy operation immediatelly after filling. In original case it not work because you fill this value without filling rest of other related values before.

by setting the "-DALL" parameter on the snmpset commnad, i could see that the

rlCopySourceFileName.0 s $rlCopySourceFileName \

line was throwing off things.  because the $rlCopySourceFileName variable was blank, the next OID, rlCopySourceFileType.0, was being used as the value.  from there the ordinal positioning of all items was off and that is what caused the issue.

the relevant command is now:

snmpset -v2c -c $string -m +/usr/share/snmp/mibs/CISCOSBcopy.mib $host \
    rlCopyRowStatus.0 i $rlCopyRowStatus \
    rlCopySourceLocation.0 i $rlCopySourceLocation \
    rlCopySourceIpAddress.0 a $rlCopySourceIpAddress \
    rlCopySourceUnitNumber.0 i $rlCopySourceUnitNumber \
    rlCopySourceFileType.0 i $rlCopySourceFileType \
    rlCopyDestinationLocation.0 i $rlCopyDestinationLocation \
    rlCopyDestinationIpAddress.0 a $rlCopyDestinationIpAddress \
    rlCopyDestinationUnitNumber.0 i $rlCopyDestinationUnitNumber \
    rlCopyDestinationFileName.0 s $rlCopyDestinationFileName

the issue i now have is getting my tftp server to allow new files to be created.  right now the access controls and configs only allow me to write to files that already exist.  but that is not a topic for this board.