sshutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sshutil provides helpers for running commands over SSH connections.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout is the default command execution timeout. Defaults to 10 seconds.

Variables

This section is empty.

Functions

func Quote

func Quote(s string) string

Quote returns a shell-escaped version of s, safe to use as a single argument in a POSIX shell command (e.g. via ssh).

func RunWithContext

func RunWithContext[T any](ctx context.Context, f func() (T, error)) (T, error)

RunWithContext runs a function f in a separate goroutine and returns its result or returns a context error if the context is canceled before f completes.

Types

type Result

type Result struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exit_code,omitempty"`
	Error    string `json:"error,omitempty"`
}

func Run

func Run(ctx context.Context, client *ssh.Client, command string, opts RunOptions) (Result, error)

func (Result) Text

func (r Result) Text() string

type RunOptions

type RunOptions struct {
	Timeout time.Duration
	Logger  *slog.Logger
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL