Need your assistance, to find the bug in the function.
Function usage erroring out even after passing parameters.
usage() {
if [ "$1" != 0 ] || [ "$2" != 0 ]; then
echo "************************************************************"
echo " CHECK USAGE FOR CORRECT PARAMETERS "
echo "************************************************************"
echo
echo " USAGE: "
echo " $BASENAME <OPTION> <SERVICE_NAME> "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in 76S DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS."
else
echo
echo "***********************************************************************************************"
echo " Searching for the "$2" XML in Request "
echo "***********************************************************************************************"
echo
fi
}
usage
exit
#Validate the Service Name from
#
function serachFilePattern() {
#check for service name in Filepattern depending on the option(Live/Archive)
#
case $OPTRG in
-L | -l)
ServiceName=`egrep -i $SERVICE_NAME ${liveFilePattern}`
status=$?
if [ $status -ne 1 ]
then
echo " "
echo "***Found the service logging in APP***"
cd ${LOG_DIR}
stat=$?
if [ $stat -ne 1 ]
then
echo " "
echo "Change directory to path : `pwd` is SUCCESSFULL"
echo " "
fi
while read mLine
do
n="1 2 3 4 5"
logFile="${SERVICE_NAME}_LoggerGroup"
for i in $n
do
echo "**********************************************************"
echo "My line: $mLine"
searchString=`egrep -i "$mLine" "${logFile}$i"`
status=$?
echo "**********************************************************"
if [ $status -ne 1 ]
then
echo "Search string Found $i: ${searchString}"
else
echo "Search String not found in $i"
fi
done
done < "${myString}"
else
echo "String does not exist in INPUT FILE or FILE IS EMPTY "
fi
;;
-A | -a)
ServiceName=`egrep -i $SERVICE_NAME ${archFilePattern}`
status=$?
if [ $status -ne 1 ]
then
echo " "
echo "***Found the service logging in APP ***"
cd ${LOG_DIR}
stat=$?
if [ $stat -ne 1 ]
then
echo " "
echo "Change directory to path : `pwd` is SUCCESSFULL"
echo " "
fi
while read mLine
do
n="1 2 3 4 5"
logFile="${SERVICE_NAME}_LoggerGroup"
for i in $n
do
echo "**********************************************************"
echo "My line: $mLine"
searchString=`gzegrep -i "$mLine" ${logFile}$i*.log.gz`
status=$?
echo "**********************************************************"
if [ $status -ne 1 ]
then
echo "Search string Found $i: ${searchString}"
else
echo "Search String not found in $i"
fi
done
done < "${myString}"
else
echo "String does not exist in INPUT FILE or FILE IS EMPTY"
fi
;;
*)
usage
echo " Please check for correct Parameter from the Usage "
;;
esac
}
serachFilePattern
exit
Output of the Script when using all the parameters.
$ ./xmlSearch.sh -l SERVICE_NAME
************************************************************
CHECK USAGE FOR CORRECT PARAMETERS
************************************************************
USAGE:
xmlSearch.sh <OPTION> <SERVICE_NAME>
<SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APP DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS.
$ echo $?
0