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 ""
for (i = 1; i <= numfields; i++) {
content = substr($0, fstart[i], fwidth[i])
print " " content ""
}
print ""
}
}'

Of course that's just an example. You still have to
produce "" 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/lis...freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscribe@freebsd.org"