From f1792861383f7b6a6bd2df3e4c68b5028638fe5c Mon Sep 17 00:00:00 2001 From: onryo Date: Sun, 12 May 2024 01:29:51 +0200 Subject: [PATCH] Add check_status.sh --- check_status.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 check_status.sh diff --git a/check_status.sh b/check_status.sh new file mode 100644 index 0000000..4b88639 --- /dev/null +++ b/check_status.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +check_ip() { + local ip=$1 + local port=$2 + local attempts=$3 + local delay=$4 + + local result="" + local succeeded=0 + local half_attempts=$((attempts/2)) + + for ((i=1; i<=attempts; i++)); do + result=$(nc -vz -w1 "$ip" "$port" 2>&1) + if echo "$result" | grep -q "succeeded"; then + succeeded=$((succeeded+1)) + fi + sleep "$delay" + done + + if [ "$succeeded" -gt "$half_attempts" ]; then + echo "Online" + else + echo "Offline" + fi +} + +while IFS=',' read -r lat lon company city ip status version; do + new_status=$(check_ip "$ip" 18030 5 2) + echo "$lat,$lon,$company,$city,$ip,$new_status,$version" +done < nodes.dat \ No newline at end of file