Documentation
¶
Overview ¶
Package execmd provides a wrapper around https://golang.org/pkg/os/exec/ to execute commands in a shell, pipe stdout and stderr to the console with prefixes, and record output buffers.
Index ¶
- type ClusterCmd
- type ClusterRes
- type ClusterSSHCmd
- func (c *ClusterSSHCmd) Run(command string, timeout ...time.Duration) (results []ClusterRes, err error)
- func (c *ClusterSSHCmd) RunOneByOne(command string, timeout ...time.Duration) (results []ClusterRes, err error)
- func (c *ClusterSSHCmd) Start(command string, timeout ...time.Duration) (results []ClusterRes, err error)
- func (c *ClusterSSHCmd) Wait() error
- type Cmd
- type CmdRes
- type SSHCmd
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClusterCmd ¶
ClusterCmd wraps SSHCmd and preserves the host name, and saves errors from .Start() for the .Wait() method.
type ClusterRes ¶
ClusterRes contains the results of the command execution.
type ClusterSSHCmd ¶
type ClusterSSHCmd struct { Cmds []ClusterCmd Errors []error Cwd string StopOnError bool }
ClusterSSHCmd is a wrapper on SSHCmd that allows executing commands on multiple hosts in parallel or sequentially.
func NewClusterSSHCmd ¶
func NewClusterSSHCmd(hosts []string) *ClusterSSHCmd
NewClusterSSHCmd initializes ClusterSSHCmd with defaults.
func (*ClusterSSHCmd) Run ¶
func (c *ClusterSSHCmd) Run(command string, timeout ...time.Duration) (results []ClusterRes, err error)
Run executes a command in parallel on all hosts and waits for the results. The command starts simultaneously on each host. It returns results and the first caught error. To see underlying SSHCmd command errors, access the .Cmds attribute.
func (*ClusterSSHCmd) RunOneByOne ¶
func (c *ClusterSSHCmd) RunOneByOne(command string, timeout ...time.Duration) (results []ClusterRes, err error)
RunOneByOne executes a command in series: run at the first host, then run at the second host, and so on. It returns results and the first caught error. To see underlying SSHCmd command errors, access the .Cmds attribute.
func (*ClusterSSHCmd) Start ¶
func (c *ClusterSSHCmd) Start(command string, timeout ...time.Duration) (results []ClusterRes, err error)
Start executes a command in parallel on all hosts without waiting for the results. The command starts simultaneously on each host. It returns results and the first caught error.
func (*ClusterSSHCmd) Wait ¶
func (c *ClusterSSHCmd) Wait() error
Wait calls SSHCmd.Wait for each Cmd in the list of ClusterCmds. It returns the first caught .Wait() error ans stops if .StopOnError is true. To see underlying SSHCmd command errors, access the .Cmds attribute.
type Cmd ¶
type Cmd struct { ShellPath string Interactive bool LoginShell bool RecordStdout bool RecordStderr bool MuteStdout bool MuteStderr bool MuteCmd bool PrefixStdout string PrefixStderr string PrefixCmd string CancelFunc context.CancelFunc Cmd *exec.Cmd }
Cmd is a wrapper struct around exec.Cmd that provides additional functionality such as recording and muting stdout and stderr, and customizing output prefixes.
func (*Cmd) Run ¶
Run is exec.Run() wrapper: runs command and blocks until it finishes, with an optional timeout
type SSHCmd ¶
type SSHCmd struct { Cmd *Cmd Interactive bool SSHExecutable string Host string User string Port string KeyPath string Cwd string }
SSHCmd is a wrapper on Cmd to invoke ssh commands via OpenSSH binary
func (*SSHCmd) Run ¶
Run wraps Cmd.Run(), executing the remote command and waiting for it to complete