Skip to content

Commit d3d28cf

Browse files
committed
updated README.md
1 parent 8c39f2e commit d3d28cf

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
**sshsync** is a fast, minimal CLI tool to run shell commands across multiple remote servers via SSH. Easily target all servers or just a specific group, great for sysadmins, developers, and automation workflows.
44

5-
> **IMPORTANT**: sshsync uses asyncssh for SSH connections. If you use passphrase-protected SSH keys, you MUST have your ssh-agent running with the keys added via ssh-add. sshsync will rely on SSH agent forwarding to authenticate with protected keys.
5+
> **IMPORTANT**:
6+
>
7+
> 1. sshsync uses asyncssh for SSH connections. If you use passphrase-protected SSH keys, you MUST have your ssh-agent running with the keys added via ssh-add. sshsync will rely on SSH agent forwarding to authenticate with protected keys.
8+
> 2. Throughout this documentation, whenever "host" is mentioned, it refers to the SSH alias defined by the `Host` directive in your `~/.ssh/config` file, not the actual hostname (`HostName` directive). sshsync uses these aliases for all operations.
69
710
## Features ✨
811

@@ -12,6 +15,7 @@
1215
- 🕒 Adjustable SSH timeout settings
1316
- 📁 **Push/pull files** between local and remote hosts
1417
- 📊 Operation history and logging
18+
- 🔍 **Dry-run mode** to preview actions before execution
1519

1620
## Installation 📦
1721

@@ -64,12 +68,16 @@ sshsync all [OPTIONS] CMD
6468
**Options:**
6569

6670
- `--timeout INTEGER` - Timeout in seconds for SSH command execution (default: 10)
71+
- `--dry-run` - Show command and host info without executing
6772

68-
**Example:**
73+
**Examples:**
6974

7075
```bash
7176
# Check disk space on all servers with a 20 second timeout
7277
sshsync all --timeout 20 "df -h"
78+
79+
# Preview which hosts would receive the command without executing
80+
sshsync all --dry-run "systemctl restart nginx"
7381
```
7482

7583
#### Execute on a Specific Group
@@ -81,12 +89,16 @@ sshsync group [OPTIONS] NAME CMD
8189
**Options:**
8290

8391
- `--timeout INTEGER` - Timeout in seconds for SSH command execution (default: 10)
92+
- `--dry-run` - Show command and host info without executing
8493

85-
**Example:**
94+
**Examples:**
8695

8796
```bash
8897
# Restart web services on production servers
8998
sshsync group web-servers "sudo systemctl restart nginx"
99+
100+
# Preview the command execution on database servers without executing
101+
sshsync group db-servers --dry-run "service postgresql restart"
90102
```
91103

92104
### File Transfer Operations
@@ -103,6 +115,7 @@ sshsync push [OPTIONS] LOCAL_PATH REMOTE_PATH
103115
- `--group TEXT` - Push to a specific group of hosts
104116
- `--host TEXT` - Push to a single specific host
105117
- `--recurse` - Recursively push a directory and its contents
118+
- `--dry-run` - Show transfer and host info without executing
106119

107120
**Examples:**
108121

@@ -112,6 +125,9 @@ sshsync push --all ./config.yml /etc/app/config.yml
112125

113126
# Push directory to web-servers group recursively
114127
sshsync push --group web-servers --recurse ./app/ /var/www/app/
128+
129+
# Preview file transfer to a specific host without executing
130+
sshsync push --host staging-db --dry-run ./db-config.json /etc/postgres/conf.d/
115131
```
116132

117133
#### Pull Files from Remote Hosts
@@ -126,6 +142,7 @@ sshsync pull [OPTIONS] REMOTE_PATH LOCAL_PATH
126142
- `--group TEXT` - Pull from a specific group of hosts
127143
- `--host TEXT` - Pull from a single specific host
128144
- `--recurse` - Recursively pull a directory and its contents
145+
- `--dry-run` - Show transfer and host info without executing
129146

130147
**Examples:**
131148

@@ -135,6 +152,9 @@ sshsync pull --group db-servers /var/log/mysql/error.log ./logs/
135152

136153
# Pull configuration directory from a specific host
137154
sshsync pull --host prod-web-01 --recurse /etc/nginx/ ./backups/nginx-configs/
155+
156+
# Preview which files would be pulled without executing
157+
sshsync pull --group web-servers --dry-run /var/log/nginx/access.log ./logs/
138158
```
139159

140160
### Configuration Management
@@ -212,6 +232,8 @@ sshsync version
212232
## Configuration 🔧
213233

214234
> sshsync stores its configuration in a YAML file located at `~/.config/sshsync/config.yaml`. It uses your existing SSH configuration from `~/.ssh/config` for host connection details and stores only group information in its own config file. Before running other commands, it's recommended to run `sshsync sync` to assign hosts to groups for easier targeting.
235+
>
236+
> **Note about hosts**: sshsync uses the SSH alias (the `Host` directive) from your `~/.ssh/config` file, not the actual hostname. This means when you specify a host in any sshsync command, you're referring to the SSH alias that you've defined in your SSH config.
215237
216238
### Configuration File Structure
217239

@@ -250,12 +272,18 @@ sshsync all "df -h"
250272
# View memory usage on all database servers with increased timeout
251273
sshsync group db-servers --timeout 30 "free -m"
252274
275+
# Preview a potentially destructive command without execution
276+
sshsync all --dry-run "sudo apt update && sudo apt upgrade -y"
277+
253278
# Push configuration files to production servers recursively
254279
sshsync push --group production --recurse ./configs/ /etc/app/configs/
255280
256281
# Pull log files from all web servers
257282
sshsync pull --group web-servers /var/log/nginx/error.log ./logs/
258283
284+
# Preview file transfers to validate paths before execution
285+
sshsync push --all --dry-run ./sensitive-config.json /etc/app/config.json
286+
259287
# Add hosts to the dev group
260288
sshsync gadd dev
261289

src/sshsync/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def push(
207207
else (
208208
config.get_hosts_by_group(group)
209209
if group
210-
else [host_obj] if host_obj is not None else []
210+
else [host_obj]
211+
if host_obj is not None
212+
else []
211213
)
212214
)
213215

@@ -283,7 +285,9 @@ def pull(
283285
else (
284286
config.get_hosts_by_group(group)
285287
if group
286-
else [host_obj] if host_obj is not None else []
288+
else [host_obj]
289+
if host_obj is not None
290+
else []
287291
)
288292
)
289293

0 commit comments

Comments
 (0)