I have a flat file with multiple lines of IP PORT. (switch.ip)
I am reading the flat file to telnet to the IP and PORT and log the session.

These are not interactive ports so as soon as I connect I get raw data coming that I need to log.

For some reason I can not get this to work.
I need to open a telnet to each line and continue collecting the data.

The thing is, once it connects to the first line it stays there, and does not go on to the rest.
So each ip port has its own log file.


exec < /var/isnms/switch.ip
while read switch port host log; do
if [ -d /var/isnms/$host ]
then
echo $host exist
else
mkdir /var/isnms/$host
fi
if [ -f /var/isnms/$host/$log ]
then
echo $log exist
echo "telnet $switch $port"
telnet $switch $port >/var/isnms/$host/$log
else
touch /var/isnms/$host/$log
echo "telnet $switch $port"
telnet $switch $port >/var/isnms/$host/$log
fi