From b32322f0f49df8e30b3b14f42c65d5a369e6bbec Mon Sep 17 00:00:00 2001 From: onryo Date: Sun, 12 May 2024 02:02:21 +0200 Subject: [PATCH] Reduce time execution If the nc command returns "succeeded" even once, there's no need to perform multiple attempts, as it confirms that the node is online. --- check_status.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/check_status.sh b/check_status.sh index 4b88639..9c417e7 100644 --- a/check_status.sh +++ b/check_status.sh @@ -8,7 +8,12 @@ check_ip() { local result="" local succeeded=0 - local half_attempts=$((attempts/2)) + + result=$(nc -vz -w1 "$ip" "$port" 2>&1) + if echo "$result" | grep -q "succeeded"; then + echo "Online" + return + fi for ((i=1; i<=attempts; i++)); do result=$(nc -vz -w1 "$ip" "$port" 2>&1) @@ -18,7 +23,7 @@ check_ip() { sleep "$delay" done - if [ "$succeeded" -gt "$half_attempts" ]; then + if [ "$succeeded" -gt "$attempts/2" ]; then echo "Online" else echo "Offline"