test if removed hosts are still online

This commit is contained in:
nervuri 2021-09-24 12:18:34 +00:00
parent c46eb8b3d0
commit c45f58fd20
Signed by: nervuri
GPG Key ID: C4769EEA7BA61672
1 changed files with 29 additions and 0 deletions

View File

@ -68,6 +68,35 @@ if [ -z "$hosts" ]; then
exit 1
fi
# Save to temporary file.
tempfile=$(mktemp)
echo "$hosts" > "$tempfile"
# Delete temporary file on exit.
finish() {
rm -f "$tempfile"
}
trap finish EXIT
# Test if removed hosts are still online.
echo "Testing removed hosts..."
for removed_host in $(diff hosts "$tempfile" | grep ^\< | cut -c 3-); do
printf "%s" "$removed_host"
# If direct connection fails, try to connect through Tor.
if agunua --no-tofu --maximum-time 20 "$removed_host" >/dev/null 2>&1 || \
agunua --socks 127.0.0.1:9050 --no-tofu --maximum-time 20 "$removed_host" >/dev/null 2>&1; then
echo " - ONLINE"
# Add removed host back.
hosts="$hosts
$removed_host"
else
echo " - offilne"
fi
done
# Sort entries again.
hosts=$(echo "$hosts" | sort)
# Save to file.
echo "$hosts" > hosts