The below check is not working:
if [ $LEN = `expr $CNPROC + $CTotal` ])
and returns expr non-numeric argument shell script.
Always it is going to else. Please tell me what is the mistake.
Earlier I was not using while so the same thing was working fine now suddenly when I did put it in the while loop it is no working.
#!/usr/bin/ksh
echo "`${BOLD}` ***** Checking Memory Utilization User*****`${UNBOLD}`"
echo "==================================================="
IFS='|'
cat configMachineDetails.txt | grep -v "^#" | while read MachineType UserName MachineName
do
export MEMORY_USAGE1=`ssh -f -T ${UserName}@${MachineName} prstat -t -s rss 1 2 | tr '%' ' '| awk '$5>5.0'`
export LEN=`echo "$MEMORY_USAGE1"|wc -l`
export CNPROC=`echo "$MEMORY_USAGE1"|grep "NPROC"|wc -l`
export CTotal=`echo "$MEMORY_USAGE1"|grep "Total"|wc -l`
if [ $LEN = `expr $CNPROC + $CTotal` ]
then
echo "`${BOLD}`**************All usages are normal !!!!!! *************`${UNBOLD}`"
else
echo "`${BOLD}`**** Memory(%) is more than 5% in MachineType $MachineType UserName $UserName
MachineName $MachineName *******`${UNBOLD}`"
echo "===================================================="
echo "$MEMORY_USAGE1"
fi
done
Put the following statements before your
ifstatement:and see what comes out. That error is alnmost invariably caused, surprisingly enough :-), by passing non-numeric data to
exprand theechostatements should tell you exactly what the problem is.For example:
Based on your comment that your output is:
it’s possible that the spaces preceding your numeric values are causing your problems. Try replacing all your occurrences of:
with:
to get rid of spaces in the
wcoutput.