在 bashscript 中终止 Curl Telnet 会话 [英] Terminate Curl Telnet session in bashscript

查看:35
本文介绍了在 bashscript 中终止 Curl Telnet 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

致力于通过 curl telnet 调用从指定主机运行脚本的各种主机实现自动 telnet 连接.

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

然而,正如 telnet 所知道的,一旦我们获得任何主机的连接状态,我们必须传递一个转义字符来终止 telnet 会话,但是在 bash 脚本中,我需要在我们收到连接/拒绝响应后立即终止会话目标端点或运行 telnet 会话几秒钟后.

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 .

通过 Curl 调用检查 telnet 连接的 PFB 脚本,所以我需要在 curl 中有任何东西,我们可以在 curl 中终止 telnet 会话,一旦我们得到在几毫秒/秒内响应或终止会话.

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.

代码:

    #!/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

推荐答案

您可以在 timeout 命令中运行它,使其在一定时间后终止.

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}"

如果它没有自行退出,将在 5 秒后终止它.

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

也许 curl 不是这项工作的正确工具.您是否考虑过使用 nc 代替?

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.

这篇关于在 bashscript 中终止 Curl Telnet 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆