execute

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: MIT Imports: 13 Imported by: 4

Documentation

Overview

Package execute tries it's best to run complex, sometimes multiline bash commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Debug prints the command being run if set to true.
	Debug = false
)

Functions

func Command

func Command(cmdString string, stdOut io.Writer, stdErr io.Writer, envs map[string]string) (int, error)

Command just executes a given cmd string to the supplied io.Writer writers. If optional envs is passed in then the expanded values will be used vs the os versions.

func CommandNoWait

func CommandNoWait(cmdString string, stdOut io.Writer, stdErr io.Writer, envs map[string]string) (*exec.Cmd, error)

CommandNoWait starts the given command but does not wait for it to finish. It returns the created exec.Command which can be used with Wait.

func GetExitStatus added in v1.1.0

func GetExitStatus(waitError error) int

GetExitStatus determines the exit status code of an err from a command that was run.

func WaitNoop

func WaitNoop(interrupt chan os.Signal, cmd *exec.Cmd)

WaitNoop accepts and waits on any signal and returns on kill signals.

Types

type SSH added in v1.1.0

type SSH struct {
	Config *SSHConfig
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

SSH holds the ssh configuration and io.

func NewSSH added in v1.1.0

func NewSSH(conf *SSHConfig, stdin io.Reader, stdout, stderr io.Writer) (*SSH, error)

NewSSH will initialize a new ssh configuration for use with RunCommand. This assumes an ssh agent is available and the proper keys have been added with ssh-add. You can check added keys with ssh-add -L

func (*SSH) RunCommand added in v1.1.0

func (s *SSH) RunCommand(cmd string, envs map[string]string) error

RunCommand will execute a command using the input environment variables. It will establish a new session on every call.

type SSHConfig added in v1.1.0

type SSHConfig struct {
	Host         string `json:"host" yaml:"host"`
	Port         int    `json:"port" yaml:"port"`
	User         string `json:"user" yaml:"user"`
	ProxyHost    string `json:"proxy_host,omitempty" yaml:"proxy_host,omitempty"`
	ProxyPort    int    `json:"proxy_port,omitempty" yaml:"proxy_port,omitempty"`
	ProxyUser    string `json:"proxy_user,omitempty" yaml:"proxy_user,omitempty"`
	IdentityFile string `json:"identity_file,omitempty" yaml:"identity_file,omitempty"`
}

SSHConfig is an individual ssh configuration for creating a connection.

Jump to

Keyboard shortcuts

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