Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 770609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:31:33+00:00 2026-05-14T18:31:33+00:00

The below check is not working: if [ $LEN = `expr $CNPROC + $CTotal`

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:31:34+00:00Added an answer on May 14, 2026 at 6:31 pm

    Put the following statements before your if statement:

    echo "[$MEMORY_USAGE1]"
    echo "[$LEN]"
    echo "[$CNPROC]"
    echo "[$CTotal]"
    

    and see what comes out. That error is alnmost invariably caused, surprisingly enough :-), by passing non-numeric data to expr and the echo statements should tell you exactly what the problem is.

    For example:

    pax> expr 1 + x
    expr: non-numeric argument
    

    Based on your comment that your output is:

    [ NPROC USERNAME SWAP RSS MEMORY TIME CPU
    Total: 143 processes, 2449 lwps, load averages: 1.76, 2.56, 2.94 
    NPROC USERNAME SWAP RSS MEMORY TIME CPU
    Total: 148 processes, 2443 lwps, load averages: 1.82, 2.57, 2.95]
    [ 4]
    [ 2]
    [ 2]
    

    it’s possible that the spaces preceding your numeric values are causing your problems. Try replacing all your occurrences of:

    |wc -l
    

    with:

    |wc -l|sed 's/ //g'
    

    to get rid of spaces in the wc output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.