From owner-freebsd-stable@FreeBSD.ORG Fri Oct 31 00:43:41 2008 Return-Path: Delivered-To: stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7755D1065677 for ; Fri, 31 Oct 2008 00:43:41 +0000 (UTC) (envelope-from eksffa@freebsdbrasil.com.br) Received: from capeta.freebsdbrasil.com.br (capeta.freebsdbrasil.com.br [201.48.151.3]) by mx1.freebsd.org (Postfix) with SMTP id A3A4E8FC1B for ; Fri, 31 Oct 2008 00:43:40 +0000 (UTC) (envelope-from eksffa@freebsdbrasil.com.br) Received: (qmail 99997 invoked from network); 30 Oct 2008 22:16:59 -0200 Received: by simscan 1.1.0 ppid: 99987, pid: 99989, t: 0.9512s scanners: clamav: 0.91.1/m: spam: 3.1.1 X-Spam-Checker-Version: SpamAssassin: -last, FreeBSD Brasil LTDA rulesets: Yes X-Spam-Status: No, hits=-1.9 required=3.7 Received: from unknown (HELO claire.bh.freebsdbrasil.com.br) (201.48.151.226) by capeta.freebsdbrasil.com.br with SMTP; 30 Oct 2008 22:16:58 -0200 Message-ID: <490A4E6F.1040506@freebsdbrasil.com.br> Date: Thu, 30 Oct 2008 22:16:47 -0200 From: Patrick Tracanelli Organization: FreeBSD Brasil LTDA User-Agent: Thunderbird 2.0.0.0 (X11/20070612) MIME-Version: 1.0 To: Eduardo Meyer References: <200810301418.m9UEIvSj086321@lurza.secnetix.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: 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 00:43:41 -0000 Eduardo Meyer escreveu: [...] > Now my next problem, do the sabe with sockstat.... > > %sockstat | head -4 > USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS > freebsdsupportsshd 57255 3 tcp4 172.16.0.225:22 172.16.0.69:63583 > freebsdsupportsshd 57255 4 stream -> ?? > root sshd 57253 3 tcp4 172.16.0.225:22 172.16.0.69:63583 > > So I have the USER and COMMAND column "merged" in a single string, > because username is large. Again, space can not be used as a > separator, but hopefully only the patterns with "->" will have space > if not a column separator, easier to parse. > > But sockstat have no formatting option to be issued like -o from > ps(1). Measing in the very first sockstat output, I dont know what to > do... :( You wont be able to parse it. I believe sockstat was written when username was limited to 8 chars. Therefore, it will count until the 9th position to print another space. I dont know if patching is an option for you, but you can truncate the username printing up to 8 chars. This is the huge patch which will make your output look better and get fully parseable: --- sockstat.c.orig 2007-06-16 17:24:55.000000000 -0300 +++ sockstat.c 2008-10-30 21:57:05.000000000 -0200 @@ -586,7 +586,7 @@ if ((pwd = getpwuid(xf->xf_uid)) == NULL) pos += xprintf("%lu", (u_long)xf->xf_uid); else - pos += xprintf("%s", pwd->pw_name); + pos += xprintf("%.8s", pwd->pw_name); while (pos < 9) pos += xprintf(" "); pos += xprintf("%.10s", getprocname(xf->xf_pid)); -- Patrick Tracanelli FreeBSD Brasil LTDA. Tel.: (31) 3516-0800 316601@sip.freebsdbrasil.com.br http://www.freebsdbrasil.com.br "Long live Hanin Elias, Kim Deal!"