From owner-freebsd-stable@FreeBSD.ORG Fri Oct 31 17:57:30 2008 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 811AC1065687 for ; Fri, 31 Oct 2008 17:57:30 +0000 (UTC) (envelope-from fbsdq@peterk.org) Received: from poshta.pknet.net (poshta.pknet.net [216.241.167.213]) by mx1.freebsd.org (Postfix) with SMTP id 251D68FC12 for ; Fri, 31 Oct 2008 17:57:30 +0000 (UTC) (envelope-from fbsdq@peterk.org) Received: (qmail 14675 invoked from network); 31 Oct 2008 17:30:48 -0000 Received: from poshta.pknet.net (HELO mail.pknet.net) (216.241.167.213) by poshta.pknet.net with SMTP; 31 Oct 2008 17:30:48 -0000 Received: from 216.241.167.212 (SquirrelMail authenticated user fbsdq@peterk.org) by webmail.pknet.net with HTTP; Fri, 31 Oct 2008 11:30:48 -0600 (MDT) Message-ID: <64567.216.241.167.212.1225474248.squirrel@webmail.pknet.net> Date: Fri, 31 Oct 2008 11:30:48 -0600 (MDT) From: "Peter" To: "Eduardo Meyer" User-Agent: SquirrelMail/1.4.11 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Cc: freebsd-stable@freebsd.org Subject: Re: Script-friendly (parseble) ps(1) output? X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Oct 2008 17:57:30 -0000 >Hello, > >I need to write a cgi script which will print the output from ps(1) in >a table (html), so the average-operator can click on a KILL link and >the cgi will send the selected signal. > >I need to add one ps information per column in a table (html), >however, I found ps(1) output to be too hard to parse. There is no >separator. I believed \t was the separator but its not. > >The ps(1) command I need to use is: > >ps -ax -o pid -o user -o emul -o lstart -o lockname -o stat -o command > >Since many of those args use [:space:] in the output, I can not use >[:space:] as a separator. >Sadly, `-o fiend='value'` will only format the HEADER output, not the >values. >Ive got no clue what to do, can someone enlight me? >Thank you all in advance. -- >=========== >Eduardo Meyer >pessoal: dudu.meyer@gmail.com >profissional: ddm.farmaciap@saude.gov.br Here is something simple, and you can wrap the HTML around it...; poshta:$ps axuww | while read USER PID CPU MEM VSZ RSS TT STAT STARTED TIME COMMAND; do echo $PID $CPU $USER $COMMAND;done |head -3 PID %CPU USER COMMAND 11 89.6 root [idle] 5127 2.9 qscand spamd child (perl5.8.8) the read ignores all white space...the last variable in that 'while read' will hold everything beyond it... ie; poshta:$ps axuww| while read USER PID CPU MEM VSZ RSS TT STAT STARTED TIME; do echo $PID $CPU $USER $TIME;done |head -3 PID %CPU USER TIME COMMAND 11 77.9 root 138080:11.91 [idle] 13607 5.0 qscand 0:09.12 spamd child (perl5.8.8) etc.etc... ]Peter[