Skip to content

Commit a2e4180

Browse files
authored
feat: add output file management for per-node command results (#2)
* feat: add output file management for per-node command results * refactor: fix clippy warning about too many arguments in execute_command * fix: resolve clippy dead code warnings in ConnectionPool
1 parent 9bef6eb commit a2e4180

File tree

5 files changed

+322
-61
lines changed

5 files changed

+322
-61
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bssh"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["Jeongkyu Shin"]
66
description = "Parallel SSH command execution tool for cluster management"
@@ -22,6 +22,7 @@ indicatif = "0.18"
2222
rpassword = "7"
2323
directories = "5"
2424
dirs = "6.0"
25+
chrono = "0.4"
2526

2627
[dev-dependencies]
2728
tempfile = "3"

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A high-performance parallel SSH command execution tool for cluster management, b
1010
- **Flexible Authentication**: Support for SSH keys and SSH agent
1111
- **Host Key Verification**: Secure host key checking with known_hosts support
1212
- **Cross-Platform**: Works on Linux and macOS
13+
- **Output Management**: Save command outputs to files per node with detailed logging
1314

1415
## Installation
1516

@@ -158,6 +159,52 @@ bssh -c webservers "sudo systemctl restart nginx"
158159
bssh -c production --output-dir ./logs "tail -n 100 /var/log/syslog"
159160
```
160161

162+
## Output File Management
163+
164+
When using the `--output-dir` option, bssh saves command outputs to structured files:
165+
166+
### File Structure
167+
```
168+
output-dir/
169+
├── hostname1_20250821_143022.stdout # Standard output
170+
├── hostname1_20250821_143022.stderr # Standard error (if any)
171+
├── hostname2_20250821_143022.stdout # Per-node outputs
172+
├── hostname2_20250821_143022.error # Connection/execution errors
173+
├── hostname3_20250821_143022.empty # Marker for no output
174+
└── summary_20250821_143022.txt # Overall execution summary
175+
```
176+
177+
### File Types
178+
- **`.stdout`**: Contains standard output from successful commands
179+
- **`.stderr`**: Contains standard error output (created only if stderr is not empty)
180+
- **`.error`**: Contains error messages for failed connections or executions
181+
- **`.empty`**: Marker file when command produces no output
182+
- **`summary_*.txt`**: Overall execution summary with success/failure counts
183+
184+
### File Headers
185+
Each output file includes metadata headers:
186+
```
187+
# Command: df -h
188+
# Host: server1.example.com
189+
# User: admin
190+
# Exit Status: 0
191+
# Timestamp: 20250821_143022
192+
193+
[actual command output follows]
194+
```
195+
196+
### Example Usage
197+
```bash
198+
# Save outputs to timestamped directory
199+
bssh -c production --output-dir ./results/$(date +%Y%m%d) "ps aux | head -10"
200+
201+
# Collect system information
202+
bssh -c all-servers --output-dir ./system-info "uname -a; df -h; free -m"
203+
204+
# Debug failed services
205+
bssh -c webservers --output-dir ./debug "systemctl status nginx"
206+
```
207+
161208
## Development
162209

163210
### Building

docs/man/bssh.1

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Manpage for bssh
22
.\" Contact the maintainers to correct errors or typos.
3-
.TH BSSH 1 "August 21, 2025" "v0.2.0" "bssh Manual"
3+
.TH BSSH 1 "August 21, 2025" "v0.3.0" "bssh Manual"
44

55
.SH NAME
66
bssh \- Backend.AI SSH - Parallel command execution across cluster nodes
@@ -50,7 +50,8 @@ Maximum parallel connections (default: 10)
5050

5151
.TP
5252
.BR \-\-output\-dir " " \fIOUTPUT_DIR\fR
53-
Output directory for command results
53+
Output directory for command results. When specified, saves command outputs
54+
to separate files for each node with stdout, stderr, and execution summary
5455

5556
.TP
5657
.BR \-v ", " \-\-verbose
@@ -180,6 +181,17 @@ Use SSH agent for authentication:
180181
.TP
181182
Save output to files:
182183
.B bssh --output-dir ./results -c production "ps aux"
184+
.RS
185+
Creates timestamped files per node:
186+
.br
187+
- hostname_TIMESTAMP.stdout (standard output)
188+
.br
189+
- hostname_TIMESTAMP.stderr (error output)
190+
.br
191+
- hostname_TIMESTAMP.error (connection errors)
192+
.br
193+
- summary_TIMESTAMP.txt (execution summary)
194+
.RE
183195

184196
.SH EXIT STATUS
185197
.TP
@@ -190,6 +202,33 @@ Success - all commands executed successfully on all nodes
190202
.B 1
191203
Failure - one or more commands failed or connection errors occurred
192204

205+
.SH OUTPUT FILES
206+
When using the
207+
.B --output-dir
208+
option, bssh creates the following files:
209+
210+
.TP
211+
.I hostname_YYYYMMDD_HHMMSS.stdout
212+
Standard output from successful command execution
213+
214+
.TP
215+
.I hostname_YYYYMMDD_HHMMSS.stderr
216+
Standard error output (created only if stderr is not empty)
217+
218+
.TP
219+
.I hostname_YYYYMMDD_HHMMSS.error
220+
Error messages for failed connections or command execution
221+
222+
.TP
223+
.I hostname_YYYYMMDD_HHMMSS.empty
224+
Marker file when command produces no output
225+
226+
.TP
227+
.I summary_YYYYMMDD_HHMMSS.txt
228+
Overall execution summary with success/failure counts for all nodes
229+
230+
Each output file includes metadata headers with command, host, user, exit status, and timestamp information.
231+
193232
.SH FILES
194233
.TP
195234
.I ~/.bssh/config.yaml

0 commit comments

Comments
 (0)