Telnet of multiple server and ports

Hi,
I do a telnet to a single server using command : telnet tibserver001 9640
The output i get is :

Trying 10.19....
Connected to tibserver001

However i need to put all the servers in a single file and get the output to see if the server is connected or not.

#! /bin/bash
telnet tibserver001 9640 > output.log
telnet tibserver004 9642 >>output.log

The above does not seem to work. Is there a better way to script this ?

regards
Sam

What operating system are you using?

In what way does it not seem to work?

What output do you get from running ls -l output.log before you run your script?

What output do you get on the screen when you run your script?

What output do you get from running ls -l output.log after you run your script?

What are the contents of output.log after you run your script?

Hi,
Using Linux 5 . A change in the script which will take a input file which has servername,port. As telnet was not going into the next item in the file, i used curl instead of telnet. This works. However i am not able to get the output of the script write into the log file properly. I will have to see if i can get the output which only displays in the console be printed in the output.log file.

Input to the file is : serverlist.txt

tibserver001,9640
tibserver004,9642

Script is :trytelnet.sh -->

#!/bin/bash

if [[ $# -ne 1 ]]; then
 echo " $0 server list"
exit 1
fi

serverlist=$1
OUT=output.log
rm $OUT > /dev/null 2>&1
while IFS=, read HOST PORT
do
        echo -e "\n\n======================================================================================\n\n"
        echo Working on $HOST
        echo "Checking $HOST on Port $PORT"
        curl $HOST:$PORT --verbose >> $OUT
        echo -e "\n\n======================================================================================\n\n"
done < $serverlist

 

Execution is :

./trytelnet.sh serverlist.txt

telnet might be eating up the rest of your input file on stdin.