diff --git a/dependencies/server_alive_test.sh b/dependencies/server_alive_test.sh index 18fbce1..b4e0bc4 100644 --- a/dependencies/server_alive_test.sh +++ b/dependencies/server_alive_test.sh @@ -13,7 +13,7 @@ function online_test { # Before download if [[ $confirm_online == "true" ]]; then # Continue trying according to settings - quittime=$(( $scriptstart + $retry_download_max*60*60 )) # Hours + quittime=$(( ScriptStartTime + retry_download_max*60 )) # Minutes echo "INFO: Keep trying until $(date --date=@$quittime)" if [[ $(date +%s) -lt $quittime ]]; then echo -e "INFO: Stopping session and trying again $retry_download"mins" later\n" @@ -71,8 +71,9 @@ function online { # Function to check if the server is writable function writeable { writeable_test + local writeable_status=$? if [[ -f "$server_check_file" ]]; then rm "$server_check_file"; fi; - if [[ $? -eq 0 ]]; then + if [[ $writeable_status -eq 0 ]]; then echo -e "\e[00;32m [OK]\e[00m" is_online="0" else @@ -81,7 +82,7 @@ function writeable { # Before download if [[ $confirm_online == "true" ]]; then # Continue trying according to settings - quittime=$(( $scriptstart + $retry_download_max*60*60 )) # Hours + quittime=$(( ScriptStartTime + retry_download_max*60 )) # Minutes echo "INFO: Keep trying until $(date --date=@$quittime)" if [[ $(date +%s) -lt $quittime ]]; then echo -e "INFO: Stopping session and trying again $retry_download"mins" later\n" @@ -93,14 +94,23 @@ function writeable { queue run # Running new session fi fi + is_online="1" # Online test while [[ $retry_count -lt $retries ]]; do echo -e "\e[00;31m [RETRYING]\e[00m" let retry_count++ writeable_test + writeable_status=$? + if [[ -f "$server_check_file" ]]; then rm "$server_check_file"; fi; + if [[ $writeable_status -eq 0 ]]; then + is_online="0" + break + fi done - # If still offline - sed "3s#.*#*************************** SERVER INFO: SERVER NOT WRITEABLE#" -i $logfile - is_online="1" + # If still not writeable + if [[ $is_online -ne 0 ]]; then + sed "3s#.*#*************************** SERVER INFO: SERVER NOT WRITEABLE#" -i $logfile + is_online="1" + fi fi } \ No newline at end of file diff --git a/dependencies/server_size_management.sh b/dependencies/server_size_management.sh index a3ca52c..0b40a0c 100644 --- a/dependencies/server_size_management.sh +++ b/dependencies/server_size_management.sh @@ -34,7 +34,7 @@ function server_sizemanagement { fi done elif [[ $mode == "check" ]]; then - quittime=$(( $scriptstart + $retry_download_max*60*60 )) #hours + quittime=$(( ScriptStartTime + retry_download_max*60 )) # Minutes echo "INFO: Keep trying until $(date --date=@$quittime)" while [[ $(date +%s) -lt $quittime ]]; do echo -e "\e[00;31mERROR: Looking up free space failed for some reason!\e[00m" diff --git a/dependencies/transfer_main.sh b/dependencies/transfer_main.sh index 7d57212..8e868da 100644 --- a/dependencies/transfer_main.sh +++ b/dependencies/transfer_main.sh @@ -242,7 +242,7 @@ function transfer_already_moved { } function transfer { - local lftp_exclude quittime waittime complete_preexisting=false + local lftp_exclude quittime waittime complete_preexisting=false transfer_attempt=1 # Prepare new transfer { @@ -353,6 +353,15 @@ function transfer { break fi + # Give up when all allowed attempts are used + if [[ $transfer_attempt -ge ${retries:-3} ]]; then + echo -e "\e[00;31mERROR: Transfer failed after $transfer_attempt attempt(s)!\e[00m" + transfer_process "stop-process-bar" + queue fail + break + fi + transfer_attempt=$(( transfer_attempt + 1 )) + quittime=$(( ScriptStartTime + retry_download_max*60 )) # Check if it's time to quit @@ -365,7 +374,7 @@ function transfer { break else echo -e "\e[00;31mERROR: Transfer failed for some reason!\e[00m" - echo "INFO: Retrying until $(date --date=@$quittime '+%d/%m/%y-%a-%H:%M:%S')" + echo "INFO: Retrying until $(date --date=@$quittime '+%d/%m/%y-%a-%H:%M:%S') (attempt $transfer_attempt of ${retries:-3})" # Stop the transfer process, pause session, and retry after a delay transfer_process "stop-process-bar"