Problem Executing Firmware Command using Shell Script

Guys,

I have a script that should change one of the configuration Parameter in a http accelerator, this config change which will halt http traffic into device. So I have designed a script which should do these changes. But after executing this script, found that one of the input variable is not getting assigned & the changes are not being implementated into the accelerator device & http traffic is not being halted. So anybody do you have resolution to this issue, for which im going to have my script placed here to help you guys.

# sample Script to Outrotate the Device in Question
# Script Creation Date 01/21/2010
# Author baraghun

##*******************************************************************************************************
##  **********  FUNCTION USAGE  ***********
##*******************************************************************************************************
##

# Script name without path

BASENAME=`basename $0`

#The INFILE is going to use during the SSH

INFILE=${HOME}/config/inFile.txt

#The changes will write to OUTFILE

OUTFILE=/tmp/outFile.txt

# Functional Usage

usage() {
        echo
        echo "USAGE"
        echo "   "`basename $0`" <device> <disable|enable> "
        echo
        exit
        }
outrotate() {
        echo
        echo "OUTROTATE"
        echo "**********************************************************************"
        echo " Removing your Device `${htACC}` in Question . . . "
        echo "**********************************************************************"
        echo
}

trafficrouting() {

 #Local Variables
      #
       local STATE="$1"
      #

cat << EOF > $INFILE
po1023
pssphrase
config
switch accMode RouteTrafficACC  THIS SECTION is a FIRMWARE COM's
admin  ${STATE}
bye
bye
write memory
y
bye
goodbye
EOF
}

#
#Validate the device name
#
echo $1 | egrep "^(CMOX|PXOM|TXOM)[0-9][0-9][0-9][0-9]\-ra$" > /dev/null 2>&1
if [ $? -ne 0 ]
then
   echo
   echo "Node doesn't exist"
else
   echo "You are lucky enough"
fi
htACC="$1"

# Check the  parameters
#
[ $# -ne 2 ] && usage

# Check the input parameters
#
case $2 in

disable)
                RouteTrafficACC disable
        ;;
enable)
                RouteTrafficACC enable
        ;;
        *)
                usage
        ;;
esac


#
# Apply the changes
#
ssh -T ${htACC} < $INFILE >> $OUTFILE
#
# Remove unused files
#
chmod 777 ${OUTFILE}

Now the issue description is here

  1. Function one (usage) is being executed only with first variable (device) for which we do get a response back. But the second variable <disable|enable> is not being recognized.

  2. Since issue is with the Function one's 2 variable, function two (outrotate) is not being executed along with the function three's {STATE} & save command is not functioning to disable the device.

Here is the output of the script

$ ./outrotate.sh CMOX1234-ra disable
You are lucky enough

USAGE
   DPoutrotate.sh <device> <disable|enable>

The Log from outFile

Serial number: 1X23K00C0

ACC># Global configuration mode
ACC>(config)# ACC>[accMode](config)# Modify Multi-Protocol Gateway configuration
ACC>[accMode](config RouteTrafficACC)# Usage: admin <enabled|disabled>
ACC>[accMode](config RouteTrafficACC)# ACC>[accMode](config)# ACC>[accMode]# Unknown command or macro (write memory)
ACC>[accMode]# Unknown command or macro (bye)
ACC>[accMode]# Goodbye

So from the above logs you can figure out where the issue existing. its none other than the admin STATE.

You seem to be calling:

RouteTrafficACC disable

instead of:

trafficrouting disable

from the case statement? (same for enable)

Yes ,

Because "RouteTrafficACC" itself is a variable in that firmware. If i use "disable" option along with the variable by manually , it disable the http traffic.

According to you I need to use "trafficrouting" as a shell input to the firmware from the case statement, or else i need to replace the case function header with " RouteTrafficACC ".

Correct me if im wrong ..

Thanks in Advance

raghunsi, what I mean is that you have defined a shell function called trafficrouting that never gets called from within the validating case statement. It seems to me you need to call that function so that the command file gets generated that gets used by ssh.

Do this function variable is dependent on the case statement. Can you just rewrite that function, so that .. let me have a look into that in training environment.

The only variable used by the function is state (enable or disable) . The firmware variable RouteTrafficACC seems to be hard coded in the trafficrouting function.

Yes, firmware variable are only either " enable" or "disable", but variable's in the Firmware are not so hardcoded, so that we cannot able to change. We can change.

We have different scripts that changes the configuration also. but why this is not working .. i need to check now..

I change the function parameter, its working now without any error. But still the concern is its not able to change the Admin state in Firmware .

Need to debug now .. with firmware as well as script.

With hard coded I mean RouteTrafficACC is not an argument to the function "trafficrouting". The only argument passed to that function is enable/disable.

scruti!!. thanks for your timely assistance .. my script is working .. pretty well and changing the firmware configuration .. & stopping n starting the http traffic into device . But i guess there is some more to be added .. & feel there is bug that needs to be fixed ..

1st bug : Even though script bring back {enable} the firmware back into traffic , script display the same .

"{" Removing your Device ${htACC} in Question . . . "} .. this needs to be changed.

Viz . this should be : Removing your Device ${htACC} in Question ==> Disable
${htACC} Back into Traffic ==> Enable

2nd bug : Script it is not Echoing `${htACC}` in the output .

3rd bug: Script is not fetching the current status from output file
Output Status looks like : { admin-state disabled} from the outfile
4th bug: Need to create an separate outputfile with this format {outFile.date.devicename}.txt