batchssh

package
v0.0.0-...-5dcfad9 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SuccessIdentifier for result output.
	SuccessIdentifier = "SUCCESS"
	// FailedIdentifier for result output.
	FailedIdentifier = "FAILED"
)

Variables

This section is empty.

Functions

func WithCommandTimeout

func WithCommandTimeout(timeout time.Duration) func(*Client)

WithCommandTimeout task connection timeout option.

func WithConcurrency

func WithConcurrency(count int) func(*Client)

WithConcurrency concurrency tasks number option.

func WithConnTimeout

func WithConnTimeout(timeout time.Duration) func(*Client)

WithConnTimeout ssh connection timeout option.

func WithProxyServer

func WithProxyServer(proxyServer, user string, port int, auths []ssh.AuthMethod) func(*Client)

WithProxyServer connect remote hosts by proxy server.

Types

type Client

type Client struct {
	ConnTimeout    time.Duration
	CommandTimeout time.Duration
	Concurrency    int
	Proxy          *Proxy
}

Client for ssh.

func NewClient

func NewClient(options ...func(*Client)) *Client

NewClient session.

func (*Client) BatchRun

func (c *Client) BatchRun(
	hosts []*Host,
	sshTask Task,
) <-chan *Result

BatchRun command on remote servers.

func (*Client) ExecuteCmd

func (c *Client) ExecuteCmd(host *Host, command, lang, runAs string, sudo bool) (string, error)

ExecuteCmd on remote host.

func (*Client) ExecuteScript

func (c *Client) ExecuteScript(
	host *Host,
	srcFile, dstDir, lang, runAs string,
	sudo, remove, allowOverwrite bool,
) (string, error)

ExecuteScript on remote host.

func (*Client) FetchFiles

func (c *Client) FetchFiles(
	host *Host,
	srcFiles []string,
	dstDir, tmpDir string,
	sudo bool,
	runAs string,
) (string, error)

FetchFiles from remote host.

func (*Client) PushFiles

func (c *Client) PushFiles(
	host *Host,
	srcFiles, srcZipFiles []string,
	dstDir string,
	allowOverwrite bool,
) (string, error)

PushFiles to remote host.

type Host

type Host struct {
	Alias      string
	Host       string
	Port       int
	User       string
	Password   string
	Keys       []string
	Passphrase string
	SSHAuths   []ssh.AuthMethod
}

Host target host.

type Proxy

type Proxy struct {
	SSHClient *ssh.Client
	Err       error
}

Proxy server.

type Result

type Result struct {
	Host    string `json:"host"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

Result of ssh command.

type Task

type Task interface {
	RunSSH(host *Host) (string, error)
}

Task execute command or copy file or execute script.

Jump to

Keyboard shortcuts

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