telnet to another server

hi all,
i wanted to write a ksh script to telnet to another server on a particular port every 5 mins in order to send out an alert if that server went down.

how do i read the response that comes back when the server is down i.e "telnet: Unable to connect to remote host: Connection refused"

ta.

redirect the errors of the telnet to a file the grep for errors
If found display the appropriate error....

hey thanks for the reply, just came to mind that a telnet session if left open will get automatically shut/closed by the network. is there a better way of doing this rather than using telnet ??

ta.

you can use ping or an ftp session...

telnet and ftp uses different port, when telnetd is running, there is no guarantee that ftpd should be running or vice versa,
so ping on a telnet port is another alternative

Ex. ping is not service test. If you like to test some tcp/ip service, use that service = only correct method to check service.
And use ip and port/service number - test only service, not own dns, ...
Create socket ex. socket.sh 111.111.111.111 23

#!/usr/bin/ksh
host=$1
port=$2
exec 4<>/dev/tcp/$host/$port
exit $?

Using that nice ksh93 script, you can do something like (check.sh):

#!/usr/bin/ksh
ip=$1
port=$2
waittime=$3
while true 
do
        ./socket.sh  "$ip" "$port"  ||  ./not_ok.sh "$ip" "$port"
        sleep $waittime
done
chmod a+rx *.sh
# ex. port 23 = usually telnet, wait 300 s
./check.sh  xx.xxx.xxx.xx  23 300 >> telnet.log 2>&1     &

Now you can write your not_ok.sh script as you like.