Thank you for the assistance. This is what I came up with in the end. I had to iterate through the loop to get the trace level because sometimes the SMS parameter isn't in there.
#!/usr/bin/perl -w
use strict;
use Proc::ProcessTable;
my $t = new Proc::ProcessTable;
print "PID PPID UP START CMD TYPE
+CMD NAME TRACE\n";
foreach my $p (@{$t->table}) {
if ($p->{cmd} =~ /op01/) {
### Format time into a MM:SS format.
### accounts for single digits in seconds field
### pretty obvious, really.
my $seconds = $p->{time} % 60;
my $diff = ($p->{time} - $seconds) / 60;
my $minutes = $diff % 60;
$seconds = "0$seconds" if $seconds =~ /^\d$/;
my $bigTime = "$minutes:$seconds";
### Grab process name, type, and trace from cmd
my $output = $p->{cmd};
my @array = split( /\s+-\w\s+/, $output);
my $procType = $array[0];
my $procName = $array[1];
my $traceLevel;
for (my $i = 2; $i < @array; $i++) {
if ($array[$i] =~ /\dx(?:\d+)/) {
$traceLevel = $array[$i];
last;
}
}
$traceLevel = "N/A" if !defined($traceLevel);
my $FORMAT = "%-6s %-6s %-7s %-24s %-15s %-19s %s\n";
printf($FORMAT,
$p->{pid},
$p->{ppid},
$bigTime,
scalar(localtime($p->{start})),
$procType,
$procName,
$traceLevel);
}
}
If you make something idiot-proof, eventually someone will make a better idiot.
I am that better idiot.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.