diff --git a/common.sh b/common.sh index 7f1c219..d7529b6 100644 --- a/common.sh +++ b/common.sh @@ -158,8 +158,13 @@ wait_for_rsync() { for i in $(seq 1 "$RETRY_COUNT"); do - # stable + cross-system safe - COUNT=$(pgrep -af rsync | wc -l) + # ONLY COUNT LOCAL INITIATED RSYNC COMMANDS + COUNT=$(ps -eo pid,cmd | grep "[r]sync .*${REMOTE_SERVER:-}" | wc -l || true) + + # fallback if REMOTE_SERVER not set yet + if [[ -z "$REMOTE_SERVER" ]]; then + COUNT=$(pgrep -x rsync | wc -l || true) + fi if [[ "$COUNT" -ge "$MAX_RSYNC_PROCS" ]]; then warn "Waiting rsync slot ($COUNT/$MAX_RSYNC_PROCS)"