From 8283d43a3aadd2c219b656fe206bbcf46191863b Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sat, 22 Jun 2024 01:44:52 -0400 Subject: [PATCH] if we have really bad ping, increase ssh timeouts --- btrbk-run | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/btrbk-run b/btrbk-run index 95503a5..ce4651b 100644 --- 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 -- 2.30.2