Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: Generic Data Collection

by Anonymous Monk
on Mar 31, 2013 at 17:03 UTC ( #1026371=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Generic Data Collection
in thread Generic Data Collection

Just push the array ref instead of a string, then you can sort.

while ( <DATA> ) { my @wanted = ( split )[ 0, 5, 9 ]; $wanted[1] =~ s/\D//g; $wanted[2] = sprintf "%05s",$wanted[2]; push @parsed, \@wanted; } print "@$_\n" for sort { $a->[2] cmp $b->[2] } @parsed;
poj


Comment on Re^5: Generic Data Collection
Download Code
Re^6: Generic Data Collection
by Deep_Plaid (Acolyte) on Mar 31, 2013 at 17:37 UTC

    Excellent, POJ. This works well. I need to piece through your code to understand exactly what is doing, but I wondered if you could expand on this approach to help me in my next step. I need to identify the ten oldest PIDS and then them through another command. For simplicity, I'll just select the 2 oldest for this example. Once I identify those PIDS, I need to run the command:

    lmutil lmremove -h $PRODUCT $flexlmserver 27000 $PID[x]

    Where $PIDx would be the two oldest (or whatever # I want to select) PIDS. I'm sure this can be done using your approach, but I have no idea of the syntax. Thanks so much for your time.

      This simple example assumes you don't want to capture the output of the command or check for success
      while ( <DATA> ) { my @wanted = ( split )[ 0, 5, 9 ]; $wanted[1] =~ s/\D//g; $wanted[2] = sprintf "%05s",$wanted[2]; push @parsed, \@wanted; } my @sorted_by_time = sort { $a->[2] cmp $b->[2] } @parsed; # oldest my $LIMIT = 2; my $count = 0; for (@sorted_by_time){ my $PID = $_->[1]; system("lmutil lmremove -h $PRODUCT $flexlmserver 27000 $PID"); last if ++$count >= $LIMIT }
      poj

        I'm not worthy! I'm not worthy! Thanks, POJ. This is exactly what I need and it is working. I would like to capture output and check for success. I will work on ways to do that today, but if you have any suggestions on that, I would greatly appreciate it. You've been a great help and I have learned a lot. Thanks so much.

        I have another question about this code. Today was I was able to test this live and I have discovered there are cases where my data is not aligned correctly. I have been able to use a regex to address the problem, but the data set I am correcting is not getting loaded into the array. Here's the code:

        my $license_cmd = "lmutil lmstat -f $PRODUCT"; my @parsed; open LICENSES, "$license_cmd |" || die "Can't execute ($license_cmd) \ +n$!\n"; while (<LICENSES>) { my $data_line = $_; # Post FlexLM Version 7.0 - Find max number of licenses available if ($data_line =~ /Total of (\d+) licenses issued/) { $MAX_LIC = $1; } # Identify the lines of output that contain user license info elsif ($data_line =~ /\, start /) { # Remove leading spaces from the lines $data_line =~ s/^\s+//g; # Remove duplicate data from the lines (web logons) $data_line =~ tr/-//d; # Remove hyphens to remove the duplicat +e server name $data_line =~ s/(\b\w+\b)(\s*\1)+/$1/g; # Remove duplicate ser +ver name print "\n$data_line"; # <-- test results of data changes # Load user name, PID and Start Time into array USAGE_INFO my @USAGE_INFO = ( split)[ 0, 5, 9 ]; $USAGE_INFO[1] =~ s/\D//g; $USAGE_INFO[2] = sprintf "%05s",$USAGE_INFO[2]; push @parsed, \@USAGE_INFO; } } close LICENSES;

        The problem appears to be the line:

        my @USAGE_INFO = ( split )[ 0, 5, 9 ];

        ...is getting it's data directly from the raw data produced by the license command in the open file LICENSES. This makes sense, since I am massaging the data in $data_line. I have read up on SPLIT and array creations and have tried the following to build the @USAGE_INFO array with $data_line, but I can't seem to get it to work:

        my @USAGE_INFO = ( split )[ 0, 5, 9 ], $data_line; my @USAGE_INFO = ( split ($data_line) )[ 0, 5, 9 ];

        Any further help would be greatly appreciated. Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-07-25 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (170 votes), past polls