Hello
I'm trying to write a simple script to test if a port is up or down. It all depends
on being able to parse for the word "Connected" in an array. Try as I might, I can't
figure out why the following regex comparison won't work.
if $reply[1] =~ /Connected/ {
The code snippet is as follows:
#!/bin/perl
$host = @ARGV[0];
$port = @ARGV[1];
@reply = `echo " " | telnet $host $port`;
if $reply[1] =~ /Connected/ {
print "Port is up\n";
else
print "Port is down\n";
}
If I comment out the if statement, and just print out the variables, I see what I'm
expecting, e.g.:
...
print $reply[1]
Connected to ldsslcu151.chq.slc.ut.usa.wh.lds.
My preference would be to parse the whole array for "Connected" and not just presume
placement in any element. I tried storing the response to just a scaler (e.g., $reply
= `echo " " | telnet $host $port`;), but I'm not sure how a scalar handles <cr> or
<lf> characters. Anyway, the solution is probably obvious to someone, and I'd be
really grateful if they'd share it.
Lance
------------------------------------------------------------------------------
This message may contain confidential information, and is intended only for the use of
the individual(s) to whom it is addressed.
==============================================================================