如果在bash中使用超时,如果循环未执行,则>> [

问题描述 投票:0回答:1
我有一个使用curltimeout的bash脚本。

for element in "${array[@]}"; do if timeout 2s curl -v "telnet://$element:8888"; then echo "'$element' connected" && break fi done

脚本未进入if循环,我得到以下输出:

* About to connect() to abc001 port 8888 (#0) * Connected to abc001 * About to connect() to abc002 port 8888 (#0) * Connected to abc002 * About to connect() to abc003 port 8888 (#0) * Connected to abc003

数组具有值:

abc001 abc002 abc003

我有一个使用curl和timeout的bash脚本。用于“ $ {array [@]}”中的元素;如果超时2s curl -v“ telnet:// $ element:8888”,该怎么办;然后回显“'$ element'已连接” && break ...
linux bash shell curl timeout
1个回答
0
投票
timeout:如果命令超时,并且未设置--preserve-status,则以状态124退出。否则,以COMMAND状态退出。当返回值为0时,if的值为true。当您将curl..更改为echo curl...时,它将执行if语句。
© www.soinside.com 2019 - 2024. All rights reserved.