如果没有响应,BASH 杀死 wget

发布于 2024-10-15 21:33:55 字数 354 浏览 9 评论 0原文

我有这个代码

...
SERVERCONNECTION=$(wget --quiet -O - http://xx:[电子邮件受保护]:10001/server | grep 连接 | awk '{print $36}')

有时 url 没有响应,那么我想终止 wget 进程并将 SERVERCONNECTIION 变量设置为 0。

I have this code


...
SERVERCONNECTION=$(wget --quiet -O - http://xx:[email protected]:10001/server | grep connections | awk '{print $36}')

Sometimes the url get inresponsive, then I want to kill wget process and set SERVERCONNECTIION variable to 0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云醉月微眠 2024-10-22 21:33:55

使用--timeout=seconds为wget进程设置超时,即

SERVERCONNECTION=$(wget --timeout=5 --quiet -O - http://xx:[email protected]:10001/server | grep connections | awk '{print $36}')

Set a timeout for the wget process with --timeout=seconds, i.e.

SERVERCONNECTION=$(wget --timeout=5 --quiet -O - http://xx:[email protected]:10001/server | grep connections | awk '{print $36}')
满意归宿 2024-10-22 21:33:55

grep 的另一个无用用途。

使用 awk '/connections/ {print $36}' 代替,以便整行读取

wget --timeout=5 --quiet -O - http://xx:[email protected]:10001/server | awk '/connections/ {print $36}'

Another useless use of grep.

Use awk '/connections/ {print $36}' instead, so that the whole line reads

wget --timeout=5 --quiet -O - http://xx:[email protected]:10001/server | awk '/connections/ {print $36}'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文