Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Trying to sort output

by Stumpd (Initiate)
on Feb 23, 2013 at 16:01 UTC ( #1020321=perlquestion: print w/ replies, xml ) Need Help??
Stumpd has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks! I have a question on how to sort some output so I can return the correct value. I have tried several different things, including "greping" for different words and trying to sort the output in that fashion, but the problem is based on the names of the volumes in the tape library sometimes the numbers I need to check against are on a different line. It was suggest to me to remove all the carriage returns, then somehow compare the output against the threshold of seconds. Which in this case is 1001. Let me show you the output:

Process Process Description Status + Number -------- -------------------- ---------------------------------------- +--------- 69 Backup Storage Pool Primary Pool TAPE_BACKUP, Copy Pool TAPE +_OFFSITE, Files Backed Up: 36081, Bytes Backed Up +: 27,770,282,615, Unreadable Files: 0, Un +readable Bytes: 0. Current Physical File (bytes) +: 8,409,734,275 Waiting for access to inp +ut volume 300082 (3116 seconds). Current output v +olume: 300724. + 70 Backup Storage Pool Primary Pool TAPE_BACKUP, Copy Pool TAPE +_OFFSITE, Files Backed Up: 39, Bytes Backed Up: + 330,587,389,610, Unreadable Files: 0, U +nreadable Bytes: 0. Current Physical File (bytes) +: 10,636,058,581 Current input volume: 30 +0082. Current output volume: 300412. + 71 Space Reclamation Offsite Volume(s) (storage pool TAPE_OFF +SITE), Moved Files: 8401, Moved Bytes: 851,107 +,244, Unreadable Files: 0, Unreadable Bytes: +0. Current Physical File (bytes): 4,356,81 +3 Waiting for access to input volume 300082 (1843 + seconds). Current output volume: 300351 +.

This is the output from a command ran on the AIX command line to get the current processes running in our backup utility. I need to return a value if wait seconds are above 1001. However, since the spacing of these outputs and carriage returns is dynamic based on the name of process waiting what I wrote using grep only works in certain situations and even then I am not sure I am evaluating the string correctly. I use "ge" to do that, which as I understand it, evaluates the numerical value of the string. It is my hope some awesome Monk here knows a much better and easier way of doing this, because I am stumped!!! Thank you. Also I am going to add the code I currently use at the bottom here. Which does not work as it needs too. Thanks again!!!

#!/usr/bin/perl my $rundsm = "dsmadmc -id=reports -pa=reports q proc | grep Waiting"; my @output = `$rundsm`; my $string = "Waiting call (1001"; if (@output gt $string) { print "Message: Issue Found, Alert Operators\n"; print "Statistic: 1\n"; } else { print "Message: No Issues Found\n"; print "Statistic: 0\n"; } exit 0;

Comment on Trying to sort output
Select or Download Code
Re: Trying to sort output
by RichardK (Priest) on Feb 23, 2013 at 17:07 UTC

    What do you think this is going to do ?

    if (@output gt $string) {

    @output in scalar context returns the size of the array, and you compare it against a string ?

      I thought it was going to compare the two strings numerically. I am sure I do not understand this correctly. I am pretty new to this. What would be a better way of pulling out the wait seconds from that output and comparing them again the value of 1001 seconds?
Re: Trying to sort output
by Laurent_R (Parson) on Feb 23, 2013 at 18:40 UTC

    Hi, I have given you a proposed solution on your cross post on Perl Gurus.

      I have as well, and for completeness, will post it here also.

      #!/usr/bin/perl use strict; use warnings; use List::Util qw(max); my $rundsm = `dsmadmc -id=reports -pa=reports q proc`; my @seconds = $rundsm =~ /\((\d+)\s+seconds\)/mg; if (max(@seconds) >= 1001) { print "Message: Issue Found, Alert Operations\n", "Statistic: 1\n"; exit 1; } else { print "Message: No Issues Foun\n", "Statistic: 0\n"; exit 0; }

        Here's a variant that doesn't require List::Util, as you can grep the captured seconds for values greater than or equal to a limit. The m modifier's not needed in the regex, since \s+ will match across lines:

        #!/usr/bin/perl use strict; use warnings; my $limit = 1001; my $rundsm = `dsmadmc -id=reports -pa=reports q proc`; if ( isIssue( $limit, $rundsm ) ) { print "Message: Issue Found, Alert Operations\n", "Statistic: 1\n" +; exit 1; } else { print "Message: No Issues Found\n", "Statistic: 0\n"; exit 0; } sub isIssue { my ( $limit, $data ) = @_; return grep $_ >= $limit, $data =~ /\((\d+)\s+?seconds\)/g; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1020321]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-12-28 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls