Results 1 to 2 of 2
Hi,
I have written below mentioned script in perl for monitoring a service on the server. I need to monitor multiple services likewise. But the values assined to variable status ...
- 06-26-2007 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 23
perl script misbehaving
Hi,
I have written below mentioned script in perl for monitoring a service on the server. I need to monitor multiple services likewise. But the values assined to variable status is 0 instead of the output of the command. Therefore the if condition after that also goes wrong
---------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
my $status=system "nmap 192.168.32.240 -p 80 | grep 80 | cut -d \' \' -f2";
print "\n$status\n";
if ( $status eq "open" )
{
print "http on R240 is open\n";
}
else
{
print "http on R240 is closed\n";
}
--------------------------------------------------------------------------------------------------------------------------
Kindly let me know what cud the issue. Please helpLast edited by me_spearhead; 06-26-2007 at 11:36 AM. Reason: different script
- 06-28-2007 #2
Yup. system executes a command and returns the command's exit value.
What you want to do is use backquotes instead. This means "Execute this external command, and return its STDOUT":
Code:#!/usr/bin/perl my $status=`nmap 192.168.32.240 -p 80 | grep 80 | cut -d \' \' -f2`; print "\n$status\n"; if ( $status eq "open" ) { print "http on R240 is open\n"; } else { print "http on R240 is closed\n"; }DISTRO=Arch
Registered Linux User #388732


Reply With Quote