Date: Thu, 30 Oct 2008 22:16:47 -0200 From: Patrick Tracanelli <eksffa@freebsdbrasil.com.br> To: Eduardo Meyer <dudu.meyer@gmail.com> Cc: stable@freebsd.org Subject: Re: Script-friendly (parseble) ps(1) output? Message-ID: <490A4E6F.1040506@freebsdbrasil.com.br> In-Reply-To: <d3ea75b30810301303y8657f65vd6165f0650ea2bb5@mail.gmail.com> References: <d3ea75b30810291502h716ae979r9906a7a053ec5f56@mail.gmail.com> <200810301418.m9UEIvSj086321@lurza.secnetix.de> <d3ea75b30810301303y8657f65vd6165f0650ea2bb5@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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!"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?490A4E6F.1040506>