I have looked through the search results and have the following based on an existing script.
#!/bin/sh
set -vx
read line < portTest
OIFS=$IFS
IFS=#;
for i in $line;
do
# check for open ports #
connTest=`echo " " |telnet "$i"`
if [ "`echo $connTest | awk '{ print $3 }` " = "Connected" ]
then
echo "$connTest port is up"
else
echo "$connTest port is down"
fi
done
This refers to a file "portTest" which looks like this:
139.xxx.xxx.xxx 7001#139.xxx.xxx.xxx 7011#139.xxx.xxx.xxx 2001#
If I echo the variable $i earlier in the script than the telnet command it prints the whole value up to #, but when it sends the telnet request the port is not included.
I am running this on a Solaris 5.10 host which I have limited rights to.
I know this is not pretty / the right way of doing it. But my scripting knowledge (as you can see) is very limited and I just want something quick and dirty.