From owner-freebsd-questions@FreeBSD.ORG Mon Dec 17 14:00:05 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E44916A418 for ; Mon, 17 Dec 2007 14:00:05 +0000 (UTC) (envelope-from patrick_dkt@yahoo.com.hk) Received: from web54307.mail.re2.yahoo.com (web54307.mail.re2.yahoo.com [206.190.49.117]) by mx1.freebsd.org (Postfix) with SMTP id 674B413C455 for ; Mon, 17 Dec 2007 14:00:05 +0000 (UTC) (envelope-from patrick_dkt@yahoo.com.hk) Received: (qmail 74205 invoked by uid 60001); 17 Dec 2007 14:00:01 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.hk; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=XoB1eq6f4jJ6hi96a2R6A8j7u8E7MjRXapM5NR4UoC0WA1piPmE3kXru++5a4O6amo5LVjz4Tj4VHy7w+jd4ysTgApsdna0Qf9ZOHBJIrNQ+duJFesOly6ZJGsyL8gJv9ps/hiea2hcN0llcfjEb//Wy59f28CsOLWBE9hQhEy4=; X-YMail-OSG: 78IOKIsVM1mRQrbbRJ8tha.vm4Ugd3.bVwxPeK7HJz.99XboJ5kfjvlEXIx4mgn6DPwXZ8E_27S3ROVpaGXtyyT_jEbTujHOPT44AZ5q305L9_BAWtBRnFD_TxaRb_a_ Received: from [61.15.61.52] by web54307.mail.re2.yahoo.com via HTTP; Mon, 17 Dec 2007 06:00:01 PST Date: Mon, 17 Dec 2007 06:00:01 -0800 (PST) From: Patrick Dung To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <637609.73206.qm@web54307.mail.re2.yahoo.com> Subject: Re: Bash script to find out the summary of user memory usage [not working] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2007 14:00:05 -0000 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 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