1748198 Members
2717 Online
108759 Solutions
New Discussion юеВ

Re: PERL help

 
SOLVED
Go to solution
Anand_30
Regular Advisor

PERL help

Hi,

Please find below the PERL script:

#!/opt/perl/bin/perl -w

my @wlnparr = `cat wlnp_ip`;

foreach(@wlnparr)
{

my @logarr = `rsh $_ cat /tmp/TC1207*`;

foreach(@logarr)
{
my @tmparr = split(/;/,$_);
print $tmparr[1]."\n";
}
}

The host name of the servers are present in wlnp_ip.

Whenever I execute this script, the server is hung and I get the message
"ioctl TIOCFLUSH: Invalid argument".

Please help.

Thanks,
Anand
2 REPLIES 2
Hein van den Heuvel
Honored Contributor

Re: PERL help

Does the command "rsh cat /tmp/TC1207*" itself work outside perl? Where is the * resolved? locally or remotely? You may need some quotes.

Do you not need to chomp the newline of the cat data?

Minor comments.... why for a process, activate and image, for something perl can do natively? In you cat, that initial `cat`. Why not something like:
open WLN,"@wlnparr=;

Why instantiate the arrays.Of course they may be useful if you have to combine data later on, but in the examlpe you could just process the data as it arrives:

And you coudl re-arrange the loop some and just provide the list as argument:

while (<>) {
chomp;
foreach $line (`rsh $_ ... `) {
foreach $word (split(/;/,$line)) {
print...
}
}
}

and consider using: print (split(/;/,$line))[1] ...

fwiw,
Hein.


H.Merijn Brand (procura
Honored Contributor
Solution

Re: PERL help

1. Chomp
2. use strict
3. more perlish
--8<---
#!/opt/perl/bin/perl

use strict;
use warnings;

@ARGV = ("wlnl_ip");
while (<>) {
chomp (my $ip = $_); # Important! clip the newline
open my $tc, "rsh $host cat /tmp/TC1207* |";
while (<$tc>) {
chomp;
my @tmparr = split m/;/, $_;
print "$tmparr[1]\n";
}
}
-->8---

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn