Veritas-bu

[Veritas-bu] NB Perl scripting

2002-03-02 09:14:30
Subject: [Veritas-bu] NB Perl scripting
From: plb AT iotk DOT com (Peter L. Buschman)
Date: Sat, 02 Mar 2002 15:14:30 +0100
--=====================_78494899==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed


Rolf:

You can do this quite easily with the NBUX tool kit.

#!/usr/bin/perl

use NBUX;

%media = bpmedialist();

foreach $id (keys %media) {

   $media_id  = $media{$id}->{"media_id"};
   $allocated = $media{$id}->{"allocated"};

   print "$media_id $allocated\n";

}

NBUX is available here:

http://sourceforge.net/projects/nbux

Regarding your Perl code below, you need to change a couple things:

1. To read the whole file into a list, use @LINES = <bpmedialist> 
(assigning a filehandle to a scalar only reads the first line.)
2. Use a foreach loop or similar to iterate over each line in the list in turn.

You could also just use a while loop like this:

while( <bpmedialist> ) {
   @line = split( /\s+/, $_ );
   .....
   ....
}

Best regards,

--PLB


At 01:07 PM 03/02/2002 -0800, Rolf wrote:
>Hi there all,
>
>I am quite new in doing scripts with Perl, so i would like your help.
>
>For example i want to extract information from the bpmedialist command to 
>get the label ID's and the expiration date.
>When i execute the bpmedialist -mlist command i get the following.
>
>Server Host = thunderbird
>
>  id     rl  images   allocated        last updated      density  kbytes 
> restores
>            vimages   expiration       last read         <------- STATUS 
> ------->
>--------------------------------------------------------------------------------
>MEDIA    1     16   02/03/2002 19:38  02/25/2002 
>08:49     4mm     16365       0
>
>
>Out of this information i thus want the "MEDIA" and the "02/03/2002" 
>information.
>
>I create the following script
>
>-----------------------------
>
>open (bpmedialist, "c:/veritas/netbackup/bin/admincmd/bpmedialist 
>-mlist|") || die "cannot open file $!/n" ;
>
>$result = <bpmedialist>;
>@line = split(/\s+/, $result);
>print @line[0];
>-----------------------------
>
>Now my problem is that this script only reads the first line of the output 
>of the bpmedialist command, thus:
>Server Host = thunderbird
>
>So when executing the command print @line[0]; i get the result "Server", 
>and with print @line[3]; i get the result "thunderbird".
>
>What should i change to read the whole file into the @line and calculate 
>wich fields i needs? (so i can use for example print @line[30] to extract 
>the MEDIA)
>
>Hope anybody can help me with this.
>
>Thanks!
>
>Rolf
>
>
>
>
>

--=====================_78494899==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<br>
Rolf:<br>
<br>
You can do this quite easily with the NBUX tool kit.<br>
<br>
#!/usr/bin/perl<br>
<br>
use NBUX;<br>
<br>
%media = bpmedialist();<br>
<br>
foreach $id (keys %media) {<br>
<br>
&nbsp; $media_id&nbsp; = $media{$id}-&gt;{&quot;media_id&quot;};<br>
&nbsp; $allocated = $media{$id}-&gt;{&quot;allocated&quot;};<br>
<br>
&nbsp; print &quot;$media_id $allocated\n&quot;;<br>
<br>
}<br>
<br>
NBUX is available here:<br>
<br>
<a href="http://sourceforge.net/projects/nbux"; 
eudora="autourl">http://sourceforge.net/projects/nbux<br>
<br>
</a>Regarding your Perl code below, you need to change a couple
things:<br>
<br>
1. To read the whole file into a list, use @LINES = &lt;bpmedialist&gt;
(assigning a filehandle to a scalar only reads the first line.)<br>
2. Use a foreach loop or similar to iterate over each line in the list in
turn.<br>
<br>
You could also just use a while loop like this:<br>
<br>
while( &lt;bpmedialist&gt; ) {<br>
&nbsp; @line = split( /\s+/, $_ );<br>
&nbsp; .....<br>
&nbsp; ....<br>
}<br>
<br>
Best regards,<br>
<br>
--PLB<br>
<br>
<br>
At 01:07 PM 03/02/2002 -0800, Rolf wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2>Hi there
all,</font><br>
&nbsp;<br>
<font face="arial" size=2>I am quite new in doing scripts with Perl, so i
would like your help.</font><br>
&nbsp;<br>
<font face="arial" size=2>For example i want to extract information from
the bpmedialist command to get the label ID's and the expiration
date.</font><br>
<font face="arial" size=2>When i execute the bpmedialist -mlist command i
get the following.</font><br>
&nbsp;<br>
<font face="arial" size=2>Server Host = thunderbird</font><br>
&nbsp;<br>
<font face="arial" size=2>&nbsp;id&nbsp;&nbsp;&nbsp;&nbsp; rl&nbsp;
images&nbsp;&nbsp; allocated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
last updated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; density&nbsp; kbytes
restores<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
vimages&nbsp;&nbsp; expiration&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last
read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;------- STATUS
-------&gt;<br>
--------------------------------------------------------------------------------<br>
MEDIA&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 16&nbsp;&nbsp;
02/03/2002 19:38&nbsp; 02/25/2002 08:49&nbsp;&nbsp;&nbsp;&nbsp;
4mm&nbsp;&nbsp;&nbsp;&nbsp; 16365&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font><br>
&nbsp;<br>
<font face="arial" size=2>Out of this information i thus want the
&quot;MEDIA&quot; and the &quot;02/03/2002&quot; 
information.</font><br>
&nbsp;<br>
<font face="arial" size=2>I create the following script</font><br>
&nbsp;<br>
<font face="arial" size=2>-----------------------------</font><br>
&nbsp;<br>
<font face="arial" size=2>open (bpmedialist,
&quot;c:/veritas/netbackup/bin/admincmd/bpmedialist -mlist|&quot;) || die
&quot;cannot open file $!/n&quot; ;</font><br>
&nbsp;<br>
<font face="arial" size=2>$result = &lt;bpmedialist&gt;;<br>
@line = split(/\s+/, $result);<br>
print @line[0];<br>
-----------------------------</font><br>
&nbsp;<br>
<font face="arial" size=2>Now my problem is that this script only reads
the first line of the output of the bpmedialist command,
thus:</font><br>
<font face="arial" size=2>Server Host = thunderbird</font><br>
&nbsp;<br>
<font face="arial" size=2>So when executing the command print @line[0]; i
get the result &quot;Server&quot;, and with print @line[3]; i get the
result &quot;thunderbird&quot;.</font><br>
&nbsp;<br>
<font face="arial" size=2>What should i change to read the whole file
into the @line and calculate wich fields i needs? (so i can use for
example print @line[30] to extract the MEDIA)</font><br>
&nbsp;<br>
<font face="arial" size=2>Hope anybody can help me with 
this.</font><br>
&nbsp;<br>
<font face="arial" size=2>Thanks!</font><br>
&nbsp;<br>
<font face="arial" size=2>Rolf</font><br>
&nbsp;<br>
&nbsp;<br>
<font face="arial" size=2>&nbsp;<br>
</font>&nbsp;<br>
&nbsp;</blockquote></html>

--=====================_78494899==_.ALT--


<Prev in Thread] Current Thread [Next in Thread>