开发者

BASH kill wget if no response

I have this code

...

SERVERCONNECTION=$(wget --quiet -O - http://xx:yy@127.0.0.1:10001/server | grep connections | awk '{print $36}')

Sometimes the url get inresponsive, then I want to kill wget process and set SERV开发者_如何学GoERCONNECTIION variable to 0.


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

SERVERCONNECTION=$(wget --timeout=5 --quiet -O - http://xx:yy@127.0.0.1:10001/server | grep connections | awk '{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:yy@127.0.0.1:10001/server | awk '/connections/ {print $36}'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜