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

Script Problem with array.

Status
Not open for further replies.

Roeckli

Technical User
Aug 3, 2002
14
NL
Hiho,

I've got some probs. With my Script. which looks like this:

#!/usr/bin/perl
system "rsh Baba disk status >output";
$volstatus="output";
open(FP,$volstatus);
while(<FP>){
# throw away \n
chomp();
$line = $_;
next unless $line =~ /^*.*/;
(@items) = $line =~ /(\w+)\s+\d/;

printf(&quot;%s\n&quot;,
$items[0]);
}

Which gives me an Output like:

Dev
dev1
dev2
dev3
(Those names can change any time!)

I would like to put each line in a separate Array. Cause each array will have his one Table.
I don’t know the output from the first Script unless the Script has been done.

Any Ideas?

Many Thanks

Daniel
 
I think you need something like;

$line =~ /(\w+)\s+\d/;
@lines = split(/ /, $line);
# And then........
for(@lines){
print $_ . &quot;\n&quot;;
}

should give you the same output as before.
 
Hi,
Thx for the reply.

Its not was I’m really looking for. I don’t need to split the output more getting it in to different arrays.

Like:

Dev0 goes to $dev0
Dev1 --- $dev1
And so on……
The outputs off those arrays are going to be in different Tables.

IMPORTANT: it does not need to be “DEV” the name can change any time.

Daniel
 
Hi,
Why don't you store the output in a 2D - array??

VGG
 
Hiho,

I sourly would if I could :)

I’m still a newbie…

I would really appreciate any Help on this.

Many Thanks

Daniel
 
greadey I haven’t seen your post… sorry!


Oki doki
Lets try again.

I got a web page, which should give out the current Status from a Servers Harddisks.
Which I get through:
system &quot;rsh 10.68.21.34 disk status >output&quot;;

(output)

Volume Block Size (bytes) Size (blocks) Size (bytes)
------ ------------------ ------------- ------------
dev0 4096 30427264 124630073344
log 4096 4346752 17804296192
oracle 4096 87013760 356408360960

I need those Device names in a webpage <tr> $nameoffdevice </tr> and also to run some other RSH. Like
system &quot;rsh 10.68.21.34 disk status $nameoffdevice &quot;; It is also possible that an Admin will add some more devices.

If tried it with the script above put I’m not able to split those output:

<empty>
<empty>
dev0
log
oracle

in separate arrays…

Is it clearer now?

Again any help will be really appreciated

Daniel
 
Hi ,

Is this what you asked for??

#!/usr/bin/perl
system &quot;rsh Baba disk status >output&quot;;
$volstatus=&quot;output&quot;;
open(FP,$volstatus);
my $index;

my @line_arr; #array to hold items in a line.

while(<FP>){
# throw away \n
chomp();
$line = $_;
next unless $line =~ /^*.*/;
(@items) = $line =~ /(\w+)\s+\d/;

$line_arr = \@items; #dereference line_arr to get
#the arrays stored.

printf(&quot;%s\n&quot;,
$items[0]);
}


//vgg
 
Hi ,
sorry ,there is small correction..

#!/usr/bin/perl
system &quot;rsh Baba disk status >output&quot;;
$volstatus=&quot;output&quot;;
open(FP,$volstatus);
my $index;

my @line_arr; #array to hold items in a line.
my $i;
while(<FP>){
# throw away \n
chomp();
$line = $_;
next unless $line =~ /^*.*/;
(@items) = $line =~ /(\w+)\s+\d/;

$line_arr[$i] = \@items; #dereference line_arr to get
#the arrays stored.
$i++;

printf(&quot;%s\n&quot;,
$items[0]);
}

vgg
 
This gives me the same output as my original script. I’m looking for a way to get each line/output (or whatever its called) to a separate TABLE in a webpage.

Like: “dev0” goes to @array1
“oracle” goes to @array2
and so on.

Daniel
 
Hi,
You can store the line as a TD value and push this td values into Tr .
Print the reference of Tr in a table.

ex.
push @table_data,$cgi->Tr([$cgi->td(...)]);
print $cgi->table(\@table_data);

You can have different arrays for different tables when
displaying on a webpage.


VGG


 
To make it clearer: (at least for me :)) That’s the page, which is called through:
<!--#include virtual=&quot;/cgi-bin/Submit0.cgi&quot; --> from an other page.
With the script I mentioned above, I would like to replace the DEV0.
BUT the script gives out ALL Devices. That’s my main Problem.

#!/usr/bin/perl
use CGI;
use CGI::Carp 'fatalsToBrowser';
$query = new CGI;
print $query->header( -type => &quot;text/html&quot;, -target => &quot;mani_frame&quot; );
print $query->start_html( -bgcolor => &quot;#DBDBDB&quot;);
print &quot;<H1></H1>\n&quot;;
&print_prompt($query);
&do_work($query);
print $query->end_html;

sub print_prompt {
my($query) = @_;

print $query->start_form;

# print &quot;<P><EM></EM><BR>&quot;;

print $query->popup_menu(-name=>'Action',
-values=>['','quota on','quota off','quota resize','quota restart'],
-default=>'quota resize');

# print &quot;<P><EM></EM> &quot;;
# print $query->popup_menu(-name=>'',
# -values=>['vol0','vol1','vol2','vol3'],
# -default=>'quota resize');
print $query->submit;
print $query->endform;
# print &quot;<HR>\n&quot;;
}

sub do_work {
my($query) = @_;
my(@values,$key);

foreach $key ($query->param) {
print &quot;<STRONG>$key</STRONG> -> &quot;;
@values = $query->param($key);
print join(&quot;, &quot;,@values),&quot;:&quot;,&quot;vol0&quot;, &quot;<BR> \n&quot;;
system &quot;rsh baba @values dev0&quot;;
}
}

Right now it works… I was just asked to give it a bit more flexibility in case of renaming a dev.


THX
Daniel

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top