Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^7: Generic Data Collection

by poj (Priest)
on Mar 31, 2013 at 19:23 UTC ( #1026377=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re^7: Generic Data Collection
Download Code
Re^8: Generic Data Collection
by Deep_Plaid (Acolyte) on Apr 01, 2013 at 11:49 UTC

    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.

Re^8: Generic Data Collection
by Deep_Plaid (Acolyte) on Apr 01, 2013 at 17:53 UTC

    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!

      try
      my @USAGE_INFO = ( split /\s+/,$data_line )[ 0, 5, 9 ];
      poj

        That did it! Thanks so much, POJ. You da man!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-08-30 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls