From: vados-dev <192440777+vados-dev@users.noreply.github.com> Date: Wed, 15 Apr 2026 11:42:08 +0000 (+0300) Subject: fix ros-diff cron non-interactive behavior X-Git-Url: https://git.vados.ru/gitweb.cgi?a=commitdiff_plain;h=e13ab842d10a792f286bb66b70a308e4c5169309;p=Mikrotiks%2FMikrotiks.git fix ros-diff cron non-interactive behavior --- diff --git a/bin/ros-diff.sh b/bin/ros-diff.sh index c1b3059..6192e1a 100755 --- a/bin/ros-diff.sh +++ b/bin/ros-diff.sh @@ -1,6 +1,7 @@ #!/bin/bash # shellcheck disable=SC1091 set -euo pipefail +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin #set +e -u #o pipefail # Add to cron @@ -45,8 +46,8 @@ CMD_SSH_ADD=$(which ssh-add) CMD_SCP=$(which scp) CMD_SFTP=$(which sftp) #export ${CMD_SSH} -eval $(CMD_SSH_AGENT) -${CMD_SSH_ADD} +# NOTE: Do not start ssh-agent/ssh-add in cron. +# Non-interactive cron jobs have no TTY and must use key-based auth via -i. ScriptName=$(basename -- "$0") # HomeDir=$HOME @@ -137,6 +138,12 @@ spinstr() local delay=0.1 local spinsym='\\||//-' local temp + if [ ! -t 1 ] || [ -z "${TERM:-}" ]; then + while kill -0 "${pid}" 2>/dev/null; do + sleep "${delay}" + done + return 0 + fi tput civis -- while ps a | awk '{print $1}' | grep -q "${pid}"; do temp="${spinsym#?}" @@ -223,7 +230,13 @@ get_connections_str() { # Require router-specific SSH key if [ -f "${DEFAULT_SSH_KEY}" ]; then - opts=(-i "${DEFAULT_SSH_KEY}" -o PasswordAuthentication=no) + opts=( + -i "${DEFAULT_SSH_KEY}" + -o PasswordAuthentication=no + -o BatchMode=yes + -o ConnectionAttempts="${DEFAULT_CONNECT_ATTEMPTS}" + -o ConnectTimeout="${DEFAULT_CONNECT_TIMEOUT}" + ) log_msg="- Info: SSH key found at $DEFAULT_SSH_KEY" log_info "${log_msg}" else @@ -231,12 +244,6 @@ get_connections_str() { log_error "${log_msg}" exit 1 fi -# if [ -n "$DEFAULT_CONNECT_ATTEMPTS" ]; then -# opts+=("-o ConnectionAttempts=${DEFAULT_CONNECT_ATTEMPTS}") -# fi -# if [ -n "$DEFAULT_CONNECT_TIMEOUT" ]; then -# opts+=("-o ConnectTimeout=${DEFAULT_CONNECT_TIMEOUT}") -# fi #opts+=("-o PreferredAuthentications=publickey" "-o StrictHostKeyChecking=no" "-o UserKnownHostsFile=/dev/null" \ #"-o GlobalKnownHostsFile=/dev/null" "-o CheckHostIP=no") # Require router host IP @@ -443,6 +450,7 @@ backup_binary() { } readarray -t lines < "$HostsFile" + for line in "${lines[@]}"; do read -r -a HR <<< "${line}" [[ ${#HR[@]} -eq 0 || -z "${HR[0]:-}" || "${HR[0]:-}" =~ ^# ]] && continue