开发者

BASH kill wget if no response

开发者 https://www.devze.com 2023-02-09 02:31 出处:网络
I have this code ... SERVERCONNECTION=$(wget --quiet -O - http://xx:yy@127.0.0.1:10001/server | grep connections| awk \'{print $36}\')

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

精彩评论

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