From 8342535886cf7cf71752db56db3fabaf6fa28223 Mon Sep 17 00:00:00 2001 From: nervuri Date: Sun, 7 Aug 2022 00:00:00 +0000 Subject: [PATCH] check if hosts file exists before testing removed hosts --- get-hosts.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/get-hosts.sh b/get-hosts.sh index b8c49a9..0ed2e75 100755 --- a/get-hosts.sh +++ b/get-hosts.sh @@ -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)