diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-03 17:09:18 +0200 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2026-02-03 17:09:34 +0200 |
| commit | d89b9e6760e2aadf9779faa6f23678f67c731e1e (patch) | |
| tree | 5e5136a70a0fd2f315c4751c31629fd97de4ece9 /cmd | |
| parent | 4cbd559c5d66a82358029dc4b00f5174c94c8ebc (diff) | |
Add SSH agent key selection and fix MapReduce outfile handling
This commit adds two major features and fixes:
1. SSH Agent Key Selection:
- Add --agentKeyIndex flag to select specific SSH agent key (0-based)
- Solves "too many authentication failures" with multiple SSH keys
- Default -1 uses all keys (backwards compatible)
- Available in dtail, dcat, dgrep, dmap commands
2. MapReduce Outfile Fixes:
- CSV files now written at every interval, not just on exit
- Proper signal handling (SIGTERM/SIGINT) with graceful shutdown
- 5-second grace period for cleanup before force exit
- Fixes issue where outfile remained as .tmp during execution
Usage:
dtail --servers host --agentKeyIndex 0 --query '...' outfile results.csv
This is particularly useful with YubiKey/hardware tokens where many
keys are loaded in the SSH agent, and for monitoring MapReduce results
in real-time as they're computed.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/dcat/main.go | 1 | ||||
| -rw-r--r-- | cmd/dgrep/main.go | 1 | ||||
| -rw-r--r-- | cmd/dmap/main.go | 6 | ||||
| -rw-r--r-- | cmd/dtail/main.go | 3 |
4 files changed, 8 insertions, 3 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go index 0c66a98..e2736d6 100644 --- a/cmd/dcat/main.go +++ b/cmd/dcat/main.go @@ -36,6 +36,7 @@ func main() { flag.BoolVar(&displayVersion, "version", false, "Display version") flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU, "How many connections established per CPU core concurrently") + flag.IntVar(&args.SSHAgentKeyIndex, "agentKeyIndex", -1, "SSH agent key index to use (-1 for all keys)") flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port") flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path") flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method") diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go index 14cfb0c..c0a91eb 100644 --- a/cmd/dgrep/main.go +++ b/cmd/dgrep/main.go @@ -40,6 +40,7 @@ func main() { flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines") flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines") flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines") + flag.IntVar(&args.SSHAgentKeyIndex, "agentKeyIndex", -1, "SSH agent key index to use (-1 for all keys)") flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port") flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path") flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method") diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go index 7500ea6..ea5f020 100644 --- a/cmd/dmap/main.go +++ b/cmd/dmap/main.go @@ -28,7 +28,8 @@ func main() { var profileFlags profiling.Flags args := config.Args{ - Mode: omode.MapClient, + Mode: omode.MapClient, + SSHAgentKeyIndex: -1, } userName := user.Name() @@ -39,6 +40,7 @@ func main() { flag.BoolVar(&displayVersion, "version", false, "Display version") flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU, "How many connections established per CPU core concurrently") + flag.IntVar(&args.SSHAgentKeyIndex, "agentKeyIndex", -1, "SSH agent key index to use (-1 for all keys)") flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port") flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection") flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path") @@ -89,7 +91,7 @@ func main() { dlog.Client.FatalPanic(err) } - status := client.Start(ctx, signal.InterruptCh(ctx)) + status := client.Start(ctx, signal.InterruptChWithCancel(ctx, cancel)) // Log final metrics if profiling is enabled if profileFlags.Enabled() { diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go index 3d363cb..188f518 100644 --- a/cmd/dtail/main.go +++ b/cmd/dtail/main.go @@ -51,6 +51,7 @@ func main() { flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines") flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines") flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines") + flag.IntVar(&args.SSHAgentKeyIndex, "agentKeyIndex", -1, "SSH agent key index to use (-1 for all keys)") flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port") flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection") flag.IntVar(&shutdownAfter, "shutdownAfter", 3600*24, "Shutdown after so many seconds") @@ -137,7 +138,7 @@ func main() { } } - status := client.Start(ctx, signal.InterruptCh(ctx)) + status := client.Start(ctx, signal.InterruptChWithCancel(ctx, cancel)) // Log final metrics if profiling is enabled if profileFlags.Enabled() { |
