On Thu, 2009-01-01 at 04:38 -0800, Duck wrote:
> I am writing a script to ping several systems and then to run nslookup
> on those that fail the ping test. How do I capture the exit status of
> the system commands. I tried something like:
>
> $status = system("nslookup xxx.xxx.xxx.xxx");
> print "$status";
>
> but this seems to print "0" every time whether the nslookup found the
> IP address or not.
>
>
As far as I can tell, nslookup always returns 0. You're going to have
to determine if it works by the response.
#!/usr/bin/perl
use strict;
use warnings;
open my $ns_fh, '-|', "nslookup xxx.xxx.xxx.xxx" or die "could not open to
nslookup: $!\n";
while( <$ns_fh> ){
# ...
}
close $ns_fh;
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication as it is about
coding.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/