Success/failure status of telnet connection

Hi,

I am running a shell script which will spawn the telnet and login.
But sometimes, the telnet session itself is not getting spawned.

My requirement is, if the telnet session is not spawned, the user must be notified that it failed.
Is there any command to capture the status of telnet connection (success/failure) so the user can be notified with an error message.

Note : This shell script is run from a Progress code.

The script used is:

#!usr/bin/expect --
set timeout 60
spawn telnet $host
expect "username"
send abc\r
expect "password"
send xyz\r
expect "cmd"
send ....
.....
expect eof

I usually spawn a watcher, which can detect lack of progress or hanging, and report and kill and restart. The watcher can be parent or nohup child &. You might need to log things very generously but simply to support the watcher. You could 'netstat -a ... |grep ...' to see the connection status, but timeout always seems to be a necessary precaution.

1 Like

Can you please explain with a script for example.

I am a beginner. Your explanation is not clear for me.
Thanks in Advance!