Browse Source

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.
onryo 2 weeks ago
parent
commit
5edb6d48b2
  1. 9
      check_status.sh

9
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"

Loading…
Cancel
Save