Re: Script-friendly (parseble) ps(1) output?
Eduardo Meyer wrote: Now my next problem, do the sabe with sockstat I think in earlier days sockstat was just a script that merged the output from netstat and fstat (or maybe some third tool, too, I don't remember). So, you might try to use netstat and fstat instead. Of course it depends on what information you exactly need from the sockstat output (if not all of it). Best regards Oliver -- Oliver Fromme, secnetix GmbH Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd If you aim the gun at your foot and pull the trigger, it's UNIX's job to ensure reliable delivery of the bullet to where you aimed the gun (in this case, Mr. Foot). -- Terry Lambert, FreeBSD-hackers mailing list. ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
On Fri, Oct 31, 2008 at 8:03 AM, Oliver Fromme [EMAIL PROTECTED] wrote: Eduardo Meyer wrote: Now my next problem, do the sabe with sockstat I think in earlier days sockstat was just a script that merged the output from netstat and fstat (or maybe some third tool, too, I don't remember). So, you might try to use netstat and fstat instead. Of course it depends on what information you exactly need from the sockstat output (if not all of it). Best regards Oliver Right, I can potentially find the sabe information with netstat. I will check if it can be safely parsed. Thank you. -- Oliver Fromme, secnetix GmbH Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd If you aim the gun at your foot and pull the trigger, it's UNIX's job to ensure reliable delivery of the bullet to where you aimed the gun (in this case, Mr. Foot). -- Terry Lambert, FreeBSD-hackers mailing list. -- === Eduardo Meyer pessoal: [EMAIL PROTECTED] profissional: [EMAIL PROTECTED] ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
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: [EMAIL PROTECTED] profissional: [EMAIL PROTECTED] 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[ ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
Eduardo Meyer wrote: 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 You should use -axww so the command is not truncated. Since many of those args use [:space:] in the output, I can not use [:space:] as a separator. Yup, that's a problem. That's why a simple awk line won't do it. You should use fixed character positions instead of field separaters for splitting fields. I think you can look at the headers (first line) to determine the field widths. All fields are left-aligned except for the PID. So your script should simply look at the first line and store the starting position of every word in an array. Using those values you can split all the data lines according to the character positions. I could provide a 3-liner in Python, but I assume you're not writing that script in Python. :-) Best regards Oliver -- Oliver Fromme, secnetix GmbH Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd C++: an octopus made by nailing extra legs onto a dog -- Steve Taylor, 1998 ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
On Wed, Oct 29, 2008 at 04:15:29PM -0700, Xin LI wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Eduardo Meyer wrote: 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? Well, first pick a language. This would be easy in PHP or Perl or other similar scripting interpreter languages. If you pick one and then study it a little - write a few simple practice scripts, you will probably quickly see how to do it. jerry Perhaps use cut(1) with -c or something similar in other scripting language? It looks like that the output is aligned. Cheers, - -- Xin LI [EMAIL PROTECTED]http://www.delphij.net/ FreeBSD - The Power to Serve! -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkkI7pEACgkQi+vbBBjt66Bi3wCgmk9chU/FIZjuBpm/57Yl7jBY D6kAoI6ZmQRdxDm7mzjale84p4uXmlmz =4FMM -END PGP SIGNATURE- ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
| By Eduardo Meyer [EMAIL PROTECTED] | [ 2008-10-30 00:04 +0200 ] 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. Another option might be to mount /proc and use that instead. See procfs(5). Regards, Aragon ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
Hi, On Thu, 30 Oct 2008 17:45:12 +0200, Aragon Gouveia [EMAIL PROTECTED] wrote: | By Eduardo Meyer [EMAIL PROTECTED] | [ 2008-10-30 00:04 +0200 ] 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. Another option might be to mount /proc and use that instead. See procfs(5). I wouldn't do that. IIRC procfs(5) is deprecated in FreeBSD. But I could be wrong... regards, Marian ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
On Thu, Oct 30, 2008 at 12:18 PM, Oliver Fromme [EMAIL PROTECTED] wrote: Eduardo Meyer wrote: 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 Thank you all. I didnt mention the language, yes, I wanted it with shell script. Sadly, no idea was completly enough, for the default ps output it simple has no pattern. No multiple-pattern would do the job safely. With kernel stuff like idle, output happens to be completly nonsense. Counting positions in a array is the way to go, but not with the default output. Things just happen to get completly trashed with long values, like idle CPU time. What I did was formating every output header like that ps -o start=.. -o lstart=.. -o args=.. etc So I could find the begining and the ending column. -o command or -o args have always to be the last option, if I dont want 'em to get truncated. So sad. Now my next problem, do the sabe with sockstat %sockstat | head -4 USER COMMANDPID 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... :( -- === Eduardo Meyer pessoal: [EMAIL PROTECTED] profissional: [EMAIL PROTECTED] ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
On Thu, Oct 30, 2008 at 12:18 PM, Oliver Fromme [EMAIL PROTECTED] wrote: Eduardo Meyer wrote: 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 Thank you all. I didnt mention the language, yes, I wanted it with shell script. Sadly, no idea was completly enough, for the default ps output it simple has no pattern. No multiple-pattern would do the job safely. With kernel stuff like idle, output happens to be completly nonsense. Counting positions in a array is the way to go, but not with the default output. Things just happen to get completly trashed with long values, like idle CPU time. What I did was formating every output header like that ps -o start=.. -o lstart=.. -o args=.. etc So I could find the begining and the ending column. -o command or -o args have always to be the last option, if I dont want 'em to get truncated. So sad. Now my next problem, do the sabe with sockstat %sockstat | head -4 USER COMMANDPID 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... :( -- === Eduardo Meyer pessoal: [EMAIL PROTECTED] profissional: [EMAIL PROTECTED] ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
Eduardo Meyer wrote: Oliver Fromme wrote: Eduardo Meyer wrote: 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 Thank you all. I didnt mention the language, yes, I wanted it with shell script. Sadly, no idea was completly enough, for the default ps output it simple has no pattern. No multiple-pattern would do the job safely. Did you actually read my suggestion? I explained that you cannot cut by pattern, but that you need to cut on field widths according to the header line. Here's a solution that implements that, using awk to do the parsing: #!/bin/sh - ps -axww -o pid -o user -o emul -o lstart -o lockname -o stat -o command | awk '{ if (NR == 1) { # Parse header line. # Build arrays fstart[] and fwidth[]. numfields = split( $0, field, / [^ ]/) - 1 fwidth[1] = length(field[1] field[2]) + 2 fstart[1] = 1 for (i = 2; i = numfields; i++) { fwidth[i] = length(field[i + 1]) + 2 fstart[i] = fstart[i - 1] + fwidth[i - 1] } fwidth[numfields] = 100 } else { # Parse data line. print tr for (i = 1; i = numfields; i++) { content = substr($0, fstart[i], fwidth[i]) print td content /td } print /tr } }' Of course that's just an example. You still have to produce table and other surrounding HTML, of course. Best regards Oliver -- Oliver Fromme, secnetix GmbH Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd File names are infinite in length, where infinity is set to 255 characters. -- Peter Collinson, The Unix File System ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
On Thu, Oct 30, 2008 at 7:14 PM, Oliver Fromme [EMAIL PROTECTED] wrote: Eduardo Meyer wrote: Oliver Fromme wrote: Eduardo Meyer wrote: 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 Thank you all. I didnt mention the language, yes, I wanted it with shell script. Sadly, no idea was completly enough, for the default ps output it simple has no pattern. No multiple-pattern would do the job safely. Did you actually read my suggestion? I explained that you cannot cut by pattern, but that you need to cut on field widths according to the header line. Yes, sure I did. This is why I replied agreeing with you. However, it was not enough, I had to format the header so I was sure the pattern would not fail. Here's a solution that implements that, using awk to do the parsing: #!/bin/sh - ps -axww -o pid -o user -o emul -o lstart -o lockname -o stat -o command | awk '{ if (NR == 1) { # Parse header line. # Build arrays fstart[] and fwidth[]. numfields = split( $0, field, / [^ ]/) - 1 fwidth[1] = length(field[1] field[2]) + 2 fstart[1] = 1 for (i = 2; i = numfields; i++) { fwidth[i] = length(field[i + 1]) + 2 fstart[i] = fstart[i - 1] + fwidth[i - 1] } fwidth[numfields] = 100 } else { # Parse data line. print tr for (i = 1; i = numfields; i++) { content = substr($0, fstart[i], fwidth[i]) print td content /td } print /tr } }' Of course that's just an example. You still have to produce table and other surrounding HTML, of course. Best regards Oliver Thank you :) I will use it as a template. -- === Eduardo Meyer pessoal: [EMAIL PROTECTED] profissional: [EMAIL PROTECTED] ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
Eduardo Meyer escreveu: [...] Now my next problem, do the sabe with sockstat %sockstat | head -4 USER COMMANDPID 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.0 -0300 +++ sockstat.c 2008-10-30 21:57:05.0 -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 [EMAIL PROTECTED] http://www.freebsdbrasil.com.br Long live Hanin Elias, Kim Deal! ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Script-friendly (parseble) ps(1) output?
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: [EMAIL PROTECTED] profissional: [EMAIL PROTECTED] ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Eduardo Meyer wrote: 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? Perhaps use cut(1) with -c or something similar in other scripting language? It looks like that the output is aligned. Cheers, - -- Xin LI [EMAIL PROTECTED] http://www.delphij.net/ FreeBSD - The Power to Serve! -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkkI7pEACgkQi+vbBBjt66Bi3wCgmk9chU/FIZjuBpm/57Yl7jBY D6kAoI6ZmQRdxDm7mzjale84p4uXmlmz =4FMM -END PGP SIGNATURE- ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Script-friendly (parseble) ps(1) output?
On Wed, 29 Oct 2008 20:02:43 -0200, Eduardo Meyer [EMAIL PROTECTED] wrote: 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. If you can use awk, it's quite simple: ps | awk -F 'NR 1 {printf(td%s/tdtd%s/tdtd%s/tdtd%s/tdtd%s/td\n, $1, $2, $3, $4, $5);}' The only problem I see is that $5, the COMMAND field, is truncated after the first space character, so command line arguments will be missing. -- Polytropon From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to [EMAIL PROTECTED]