runner

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package runner 封装系统 ssh/scp 子进程调用(非交互、超时、截断)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MuxEnabled

func MuxEnabled(opt Options) bool

MuxEnabled 报告本次调用是否实际带上 ControlMaster 参数(目录不可写或 DisableMux 时为 false)。

func RemoteHome

func RemoteHome(ctx context.Context, opt Options, host string) (string, error)

RemoteHome 通过 ssh 读取远端 $HOME。

func ShellQuote

func ShellQuote(s string) string

ShellQuote 对远端路径/workdir 做单引号包裹,防止注入。

func WrapWorkdir

func WrapWorkdir(workdir, command string) string

WrapWorkdir 生成:cd -- <dir> && <cmd>

Types

type ExecResult

type ExecResult struct {
	ExitCode  int
	Stdout    string
	Stderr    string
	Truncated bool
	// TimedOut 是否因超时被杀
	TimedOut bool
	// ConnectErr 是否更像连接/ssh 客户端失败(无远端退出码语义)
	ConnectErr bool
}

ExecResult 远程命令结果。

func SCPGet

func SCPGet(ctx context.Context, opt Options, host, remotePath, localPath string) (*ExecResult, error)

SCPGet 下载:scp [opts] host:remote local

func SCPPut

func SCPPut(ctx context.Context, opt Options, host, localPath, remotePath string) (*ExecResult, error)

SCPPut 上传:scp [opts] local host:remote

func SSHExec

func SSHExec(ctx context.Context, opt Options, host, command string) (*ExecResult, error)

SSHExec 执行:ssh [opts] host -- command command 为已拼好的远端 shell 命令字符串。

连接复用由 OpenSSH ControlMaster=auto 负责:control socket 损坏时会自动新建连接, runner 层不做额外重试;上层若需可设 Options.DisableMux 强制单次握手。

type Options

type Options struct {
	SSHConfig string // -F 路径,空则系统默认
	Timeout   time.Duration
	// MaxStdout / MaxStderr 各自字节上限(Spec:分别上限)
	MaxStdout int
	MaxStderr int
	// DisableMux 为 true 时不传 ControlMaster 等复用参数(单测/显式回退)。
	DisableMux bool
}

Options 一次远程调用选项。

Jump to

Keyboard shortcuts

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