if we have really bad ping, increase ssh timeouts
authorIan Kelling <ian@iankelling.org>
Sat, 22 Jun 2024 05:44:52 +0000 (01:44 -0400)
committerIan Kelling <ian@iankelling.org>
Sat, 22 Jun 2024 05:44:52 +0000 (01:44 -0400)
btrbk-run

index 95503a5a994002f8836562a316ea6d8957b920bb..ce4651bce82dd96a902b5db0b5bed3c04738cff7 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -491,6 +491,22 @@ fi
 
 #### begin pre-checks #####
 
+# when we are on a plane, ping 800, wait a log longer.
+if ! pingms=$(ping -c2 8.8.8.8 2>/dev/null | sed -nr 's,^rtt .*/([1-9][0-9]*)\.[0-9]*/[^/]*$,\1,p'); then
+  wait_factor=10
+else
+  regex="^[1-9][0-9]*$"
+  if [[ $pingms =~ $regex ]]; then
+    wait_factor=$(( pingms / 20 ))
+    if (( wait_factor == 0 )); then
+      wait_factor=1
+      fi
+  else
+    wait_factor=10
+  fi
+fi
+ssh_timeout="timeout -s 9 $(( 6 * wait_factor ))"
+
 # todo: this has a timing problem, since btrbk.timer could activate the service after this check.
 if ! $fast && [[ $source ]]; then
   if [[ $(ssh $source ps --no-headers -o comm 1) == systemd ]]; then
@@ -623,7 +639,7 @@ df --output=size,pcent / | tail -n1"
       root_size=$(( 1024 * 1024 * 2000 )) #2tb
       percent_used=10
       zone=$(date +%z)
-    elif remote_str=$(timeout -s 9 6 ssh root@$h "$remote_str_cmd"); then
+    elif remote_str=$($ssh_timeout ssh root@$h "$remote_str_cmd"); then
       mapfile -t tmp_array <<<"$remote_str"
       zone="${tmp_array[0]}"
       IFS=" " read -r root_size percent_used <<<"${tmp_array[1]}"
@@ -664,7 +680,7 @@ df --output=size,pcent / | tail -n1"
     # This is a separate ssh because the command can fail and thatis ok.
     if ! $force; then
       locked=false
-      if lock_info=$(timeout -s 9 6 ssh $h DISPLAY=:0 xscreensaver-command -time); then
+      if lock_info=$($ssh_timeout ssh $h DISPLAY=:0 xscreensaver-command -time); then
         if [[ $lock_info != *non-blanked* ]]; then
           locked=true
         fi