Small Bash script for fast file synchronization from the current working directory (pwd) to one or multiple remote hosts using rsync over ssh.
It is driven by a local config file called .syncnow π.
- Syncs selected files/directories from the current directory (
SYNC_DIR = pwd) to remote host(s). - Uses
rsyncoverssh(default port22). - Requires a
.syncnowfile in the directory where you run the command. - Supports multiple destinations via
SYNC_REMOTE_HOST="host1,host2"(comma-separated list). - By default trying to sync with hostname
sync-remote-hostwhich can be resolved via/etc/hostsor DNS. You can override this by settingSYNC_REMOTE_HOST.
-
Copy the script to
/local/sbin(or any directory in yourPATH):sudo curl --url https://raw.githubusercontent.com/nchekwa/syncnow/refs/heads/main/syncnow --output /usr/local/sbin/syncnow sudo chmod +x /usr/local/sbin/syncnow
-
Make sure
/usr/local/sbinis in yourPATH:echo $PATH
-
(Optional) Set up SSH keys for the remote host:
syncnow --auth
-
In your project directory create a
.syncnowfile:cd /path/to/project touch .syncnow -
Run synchronization:
syncnow
or without confirmation prompt:
syncnow -y
The .syncnow file must exist in the directory where you run syncnow.
If it is missing, the script aborts execution.
Example configuration:
# Remote SSH user
SYNC_REMOTE_USER="deploy"
# Single or multiple hosts (comma-separated list)
SYNC_REMOTE_HOST="192.168.1.10,192.168.1.11"
# SSH port
SYNC_REMOTE_PORT="22"
# Target path on remote host (by default can be same as local SYNC_DIR)
SYNC_REMOTE_PATH="/var/www/project"
# Files/directories to sync (example)
SYNC_SOURCE_ITEMS=("src" "config" "docker-compose.yml")
# Whether to include .syncnow in the synced items (Y/N)
SYNC_DOTSYNC_CONFIG="Y"-
The script loads
.syncnowas ENV:set -a source "$SYNC_DIR/.syncnow" set +a
-
All variables from
.syncnowbecome available in the script environment. -
Key variables:
SYNC_DIRβ alwayspwd(directory from whichsyncnowis executed).SYNC_REMOTE_USERβ SSH user.SYNC_REMOTE_HOSTβ single host or comma-separated list of hosts.SYNC_REMOTE_PORTβ SSH port (currentlyrsyncuses port22directly; this variable is ready for future extension).SYNC_REMOTE_PATHβ target directory on the remote host(s).SYNC_SOURCE_ITEMSβ array of files/directories to sync.SYNC_DOTSYNC_CONFIGβ whether to include.syncnowin the synced items list.
- You run
syncnowin your project directory. - The script:
- requires
.syncnowto exist, SYNC_DIRis yourpwdby default,- loads variables from
.syncnow, - builds the host list from
SYNC_REMOTE_HOST(supports comma-separated list), - checks DNS/host resolution for each host (
getent hosts), - asks for confirmation (unless
-yis used), - runs
rsyncfor each item inSYNC_SOURCE_ITEMSto each configured host.
- requires