From owner-freebsd-questions Wed Aug 14 7:47:39 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D339B37B401 for ; Wed, 14 Aug 2002 07:47:34 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5356643E65 for ; Wed, 14 Aug 2002 07:47:34 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.5/8.12.5) id g7EElU9g092098; Wed, 14 Aug 2002 09:47:30 -0500 (CDT) (envelope-from dan) Date: Wed, 14 Aug 2002 09:47:29 -0500 From: Dan Nelson To: Tillman Hodgson Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Extracting the 1-minute loadavg in a portable yet low-impact fashion Message-ID: <20020814144729.GA50066@dan.emsphone.com> References: <20020814083253.C11913@seekingfire.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020814083253.C11913@seekingfire.com> X-OS: FreeBSD 5.0-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In the last episode (Aug 14), Tillman Hodgson said: > I'm trying to extract the 1-minute loadavg in a portable (between > RedHat Linux and FreeBSD, at least) way without having to invoke a > lot of expensive subprocesses. On Linux, awk '{print \$1}' < > /proc/loadavg has been working nicely (though non-portably). When I > log onto a BSD host and my NFS-mounted home dir follows me, this > obviously doesn't work very well :-) > > uptime | awk '{print $10}' works, but leaves a trailing comma. Adding > a sed statement to the end of that would start to get too expensive. That actually won't work, since if the system has been up for under an hour, you get 9:43AM up 28 mins, 6 users, load averages: 0.28, 0.67, 0.43 How about uptime | sed -e 's/.*: \([0-9.]*\).*/\1/' ? That should work on any system where the loadavg is immediately preceded by ": ", which is every OS I can lay my hands on at the moment. -- Dan Nelson dnelson@allantgroup.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message