check if hosts file exists before testing removed hosts

This commit is contained in:
nervuri 2022-08-07 00:00:00 +00:00
parent eb6c24c12b
commit 8342535886
1 changed files with 15 additions and 13 deletions

View File

@ -79,20 +79,22 @@ finish() {
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
if [ -f hosts ]; then
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 " - offline"
fi
done
else
echo " - offline"
fi
done
fi
# Sort entries again.
hosts=$(echo "$hosts" | sort)