Adrian
Adrian

Reputation: 2656

BASH kill wget if no response

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.

Upvotes: 1

Views: 2144

Answers (2)

Walter
Walter

Reputation: 31

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

Upvotes: 3

thevilledev
thevilledev

Reputation: 2377

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}')

Upvotes: 5

Related Questions