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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Want to pull data from file and create a hash 5

Status
Not open for further replies.

gcazian

MIS
Dec 4, 2002
61
US
Hello, I am attempting to create a filehandle that reads the output of a TSM query (tape drive status) from a file and then creates a hash table of the library drive number and its corresponding status.

Here is what the TSM output file typically looks like:

ANR8330I LTO volume 000165L1 is mounted R/O in drive MT1.0.0.3 (mt1.0.0.3), status: IN USE.
ANR8330I LTO volume 000290L1 is mounted R/W in drive MT1.0.0.2 (mt1.0.0.2), status: IN USE.
ANR8329I LTO volume 000114L1 is mounted R/W in drive MT0.0.0.2 (mt0.0.0.2), status: IDLE.

I want to create a hash table named %drvstat

So, for the above example, the hash slices would be:

$drvstat{"MT1.0.0.2"} = 'IN USE'
$drvstat{"MT0.0.0.2"} = 'IDLE'

I am a novice and am having a bit of trouble getting started, anyone willing to help a newbie out? Thanks!
 
try something like this...
Code:
my %drvstat;

if ( ! open(TSMOUT, "tsm_outfile.txt") ) {
    printf( "There was an error while opening the TSM output file: %s\n", $! );
    die "$!\n";
}

@output = <TSMOUT>;

close TSMOUT;

while ( @output ) {
    chomp ( my $line = $_ );

    # zero based
    # without the second number, everything to the end of the line is returned
    my $key   = substr( $line, 53, 9 );
    my $value = substr( $line, 84 );

    $drvstat{$key} = $value;
}


--
-- GhodMode
 
TSM.txt
[red]ANR8330I LTO volume 000165L1 is mounted R/O in drive MT1.0.0.3 (mt1.0.0.3), status: IN USE.
ANR8330I LTO volume 000290L1 is mounted R/W in drive MT1.0.0.2 (mt1.0.0.2), status: IN USE.
ANR8329I LTO volume 000114L1 is mounted R/W in drive MT0.0.0.2 (mt0.0.0.2), status: IDLE.
[/red]

open (INFILE, "< TSM.txt");
@entries = <INFILE>;
close INFILE;

foreach $entry (@entries) {

$entry =~ m|(MT\d.\d.\d.\d).* status: ([A-Z ]+).$|;

$mt = $1;
$status = $2;

$drvstat{"$mt"} = $status;
print "$mt => $status\n";

}


Kind Regards
Duncan
 
Just becuase it's been awhile and I'm bored, here's another variation:

Code:
open(IN, 'TSM.txt') or die $!;
$drvstat{$1} = $2 while <IN> =~ /MT(.+?) .*: (.*)/;
close IN;

print "$_ => $drvstat{$_}\n" for keys %drvstat;

( hey Duncan, sup! )

--jim
 
Hi Jim

how are you - haven't seen you for a while?

... showing off again... your scripts make my head hurt! nice work! ;-)


Kind Regards
Duncan
 
Me too Duncan - I'm just surprised he didn't manage to use the map() function in there somewhere... :-)

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Mike,

The teddy bear references, are they Robert Rankin references also?

--Paul
 
As requested:

%drvstat = map { /MT(.+?) .*: (.*)/ } <IN>;

I have to come back everynow and then for an ego boost - you guys are so great! Work is good though, so not much time to hang out.

talk to you later,

--jim
 
i give up ... i'm gonna get a job as a road sweeper!


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top