@@ -8,6 +8,7 @@ SSH_HOST="ssh-domain.com"
88SSH_PORT=" 22"
99REMOTE_DIR=" /home/somwhereremote"
1010SOCKET_PATH=" ${HOME} /.ssh/roles_sock"
11+ SSH_PASS=" xxxx"
1112# ---------------------
1213
1314S=" \\ "
@@ -20,6 +21,22 @@ if ! command -v fswatch >/dev/null 2>&1; then
2021 exit 1
2122fi
2223
24+ if ! command -v sshpass > /dev/null 2>&1 ; then
25+ echo " ❌ sshpass missing"
26+ echo " "
27+ echo " 👉 Install:"
28+ echo " macOS: brew install hudochenkov/sshpass/sshpass"
29+ echo " Linux: sudo apt install sshpass"
30+ exit 1
31+ fi
32+
33+ if [[ -z " ${SSH_PASS} " ]]; then
34+ echo " ❌ SSH_PASS is not set"
35+ echo " 👉 export SSH_PASS='your_password'"
36+ exit 1
37+ fi
38+ # ---------------------------
39+
2340# start SSH multiplexing
2441ssh -M -S " ${SOCKET_PATH} " -fnNT \
2542 -p " ${SSH_PORT} " " ${SSH_USER} @${SSH_HOST} "
@@ -37,14 +54,26 @@ fswatch -0 ./ | while read -d "" file; do
3754 REMOTE_PATH=" ${REMOTE_DIR} /${rel_path} "
3855
3956 if [[ -e " ${file} " ]]; then
57+ # prevent race-condition rsync on disappearing files
58+ [[ -f " ${file} " || -d " ${file} " ]] || continue
59+
4060 echo " ✅ File exists: ${file} "
4161 # --- FILE EXISTS: Sync it ---
42- CMD=" rsync -az -e \" ssh -p ${SSH_PORT} -S ${SOCKET_PATH} \" \" ${file} \" \" ${SSH_USER} @${SSH_HOST} :$REMOTE_PATH \" "
62+
63+ CMD=" sshpass -p \" ${SSH_PASS} \" rsync -az \
64+ -e \" ssh -p ${SSH_PORT} -S ${SOCKET_PATH} \" \
65+ \" ${file} \" \
66+ \" ${SSH_USER} @${SSH_HOST} :${REMOTE_PATH} \" "
67+
4368 else
4469 echo " ❌ File deleted: ${file} "
4570 # --- FILE DELETED LOCALLY: Remove remotely if it's a file ---
4671 # [ -f ... ] checks if it exists and is a regular file, then rm removes it.
47- CMD=" ssh -p ${SSH_PORT} -S ${SOCKET_PATH} ${SSH_USER} @${SSH_HOST} '[ -f \" ${REMOTE_PATH} \" ] && rm \" ${REMOTE_PATH} \" '"
72+
73+ CMD=" sshpass -p \" ${SSH_PASS} \" ssh \
74+ -p ${SSH_PORT} -S ${SOCKET_PATH} \
75+ ${SSH_USER} @${SSH_HOST} \
76+ '[ -f \" ${REMOTE_PATH} \" ] && rm \" ${REMOTE_PATH} \" '"
4877 fi
4978
5079 printf ' %s\n\n' " ${CMD} "
0 commit comments