Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Dec 2007 06:00:01 -0800 (PST)
From:      Patrick Dung <patrick_dkt@yahoo.com.hk>
To:        freebsd-questions@freebsd.org
Subject:   Re: Bash script to find out the summary of user memory usage [not working]
Message-ID:  <637609.73206.qm@web54307.mail.re2.yahoo.com>

next in thread | raw e-mail | index | archive | help
I have correction with the script but still doesn't work:

#!/usr/local/bin/bash
for user in `ps -A -o user | sort | uniq | tail +2`
 do
        echo "user: $user"

   ps aux -U $user | tail +2 | while read line
   do

    mem=`echo $line | awk {'print $4'}`
        echo "mem: $mem"
        TMPSUMMEM=`awk -v x=$mem -v y=$TMPSUMMEM 'BEGIN{printf
"%.2f\n",x+y}'`
        echo "summem: $TMPSUMMEM"
   done
        echo "finalsummem: $SUMMEM"
        export SUMMEM=$TMPSUMMEM
 done

        echo "finalsummem: $SUMMEM"

> #!/usr/local/bin/bash
> 
> for user in `ps -A -o user | sort | uniq | tail +2`
>  do
>         echo "user: $user"
> 
>    ps aux -U $user | tail +2 | while read line
>    do
> 
>     mem=`echo $line | awk {'print $4'}`
>         echo "mem: $mem"
>         TMPSUMMEM=`awk -v x=$mem -v y=$TMPSUMMEM 'BEGIN{printf
> "%.2f\n",x+y}'`
>         echo "summem: $TMPSUMMEM"
>    done
>         echo "finalsummem: $TMPSUMMEM"


--- Patrick Dung <patrick_dkt@yahoo.com.hk> wrote:

> Hello, any idea about why below script is not working?
> The final sum is empty..
> 
> #!/usr/local/bin/bash
> 
> for user in `ps -A -o user | sort | uniq | tail +2`
>  do
>         echo "user: $user"
> 
>    ps aux -U $user | tail +2 | while read line
>    do
> 
>     mem=`echo $line | awk {'print $4'}`
>         echo "mem: $mem"
>         TMPSUMMEM=`awk -v x=$mem -v y=$TMPSUMMEM 'BEGIN{printf
> "%.2f\n",x+y}'`
>         echo "summem: $TMPSUMMEM"
>    done
>         echo "finalsummem: $SUMMEM"
>  donefreebsd-questions@freebsd.org.hk
> 
> 
>      
>
____________________________________________________________________________________
> Looking for last minute shopping deals?  
> Find them fast with Yahoo! Search. 
>
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?637609.73206.qm>