0
votes

Working on automating telnet connectivity from various hosts running the script from specified host with curl telnet call.

However as are aware for telnet once we get connected status for any hosts we have to pass an escape character to terminate the telnet sessions, but in bash script I need to terminate the session as soon as we get Connected/Refused response from the target endpoint or after some seconds of running the telnet session .

PFB Script where telnet connectivity is checked through Curl call, so I need is there anyway in curl that we can terminate the telnet session in curl as soon as we get the response or terminate the session in some milliseconds/seconds.

Code:

    #!/bin/bash
    HOSTS='LPDOSPUT00100 LPDOSPUT00101'
     for S in ${HOSTS}
      do
         echo "Checking Connectivity From Host : ${S}"
         echo ""
         ssh -q apigee@${S} "curl -v telnet://${TargetEndPoint}:${Port}"
     done
1

1 Answers

1
votes

You could run it in the timeout command to make it terminate after a certain amount of time.

ssh -q apigee@"$S" "timeout 5s curl -v telnet://${TargetEndPoint}:${Port}"

would terminate it after 5 seconds if it hadn't already exited on its own.

Perhaps curl isn't the right tool for this job though. Have you considered using nc instead?

ssh -q apigee@"$S" "nc -z ${TargetEndPoint} $Port"

will likely do what you want.