Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Binary Output

Status
Not open for further replies.

jonnymp316

IS-IT--Management
Jun 6, 2003
6
US
Hi, ok so I run a program called vmquery.exe and it gives me this output:

============================================================
Media ID: SM1014
media type: DLT cartridge tape (11)
barcode: SM1014
description: ---
volume pool: SCRATCH (2)
robot type: TLD - Tape Library DLT (8)
robot number: 0
robot slot: 8
robot host: usca1cs-nb1
volume group: 00_000_TLD
created: 06/06/2003 10:45:10 PM
assigned: ---
last mounted: ---
first mount: ---
expiration date: ---
number of mounts: 0
max mounts allowed: ---
============================================================

All I want to be able to do is to get just the Media ID number from the binary output so I am using this script:

@rc=`vmquery -rn 0 -h usca1cs-nb1`;
open STORE, ">stored.txt";
my $name;
foreach $line (@rc) {
if (index $line, "media ID") {
print STORE $line;
}
}
close STORE;

All I ever get in my txt file is all the other information minus the Media ID line so it looks like this in the text file:

==================================================

media ID: SM1014
media type: DLT cartridge tape (11)
barcode: SM1014
description: ---
volume pool: SCRATCH (2)
robot type: TLD - Tape Library DLT (8)
robot number: 0
robot slot: 8
robot host: usca1cs-nb1
volume group: 00_000_TLD
created: 06/06/2003 10:45:10 PM
assigned: ---
last mounted: ---
first mount: ---
expiration date: ---
number of mounts: 0
max mounts allowed: ---
==================================================

Can anyone help. I am a perl newbie.

-Jonathan
 
I think this is the problem. Your data is not coming out as an array but as a scalar.

try this

$rc=`vmquery -rn 0 -h usca1cs-nb1`;
print $rc;
exit;
#If the above line of code produces all the same output then try this code


$rc=`vmquery -rn 0 -h usca1cs-nb1`;
my @rc = split(/\n/, $rc);
open STORE, ">stored.txt";
my $name;


print STORE $line[0];
close STORE;



haunter@battlestrata.com
 
Jonny,

Stick with the program man ...

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
What is happening is that index returns 0 when it looks at the line with 'media ID:' (it is at the start of the string). All other lines index returns -1 (string not found). Remeber in perl 0 is false. So to make it work just negate your index test and all should be well with the world.

Hope that helps.

See for a discussion of the twisted truth of perl.
 
Here is another way you could write the script that is a little more common in the perl world:
Code:
@rc=`vmquery -rn 0 -h usca1cs-nb1`;
open(STORE, "> stored.txt");

foreach $line (@rc) {
  if ($line =~ /^media ID/) {
    print STORE $_;
  }
}
close STORE;
 
Sorry, preceding example should read:
Code:
    print STORE $line;

not

    print STORE $_;
I appologize for any confusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top