Documentation ¶
Index ¶
- Constants
- Variables
- func DecryptPassphrase(passphrase string)
- func ExecCmds(gs *GoSSH, host *Host, stdout io.Writer, eo ExecOption, hostGroup string)
- func ExecInHosts(gs *GoSSH, target *Host, hostsCmd HostsCmd, stdout io.Writer, eo ExecOption, ...) error
- func ExecuteInitialCmd(initialCmd string, w io.Writer)
- func GetLastLine(s string) (preLines, curLine string)
- func IsCapitalized(str string) bool
- func Repl(gs *GoSSH, hosts []*Host, stdout io.Writer, hostGroup string)
- func StripAnsi(str string) string
- func StripAnsiBytes(b []byte) []byte
- type AnsiStripper
- type CmdChanClosed
- type CmdExcResult
- type CmdWrap
- type Config
- type DlCmd
- type EchoState
- type ExecOption
- type Extra
- type GoSSH
- type Host
- func (h *Host) Close() error
- func (h *Host) GetGosshConnect() (*gossh.Connect, error)
- func (h *Host) GetSftpClient() (*sftp.Client, error)
- func (h *Host) IsConnected() bool
- func (h *Host) IsExecModeCmdByCmd() bool
- func (h Host) PrintSCP()
- func (h *Host) PrintSSH()
- func (h *Host) Prop(name string) string
- func (h *Host) SSH(cmds []string, resultVar string, stdout io.Writer, eo ExecOption) (err error)
- func (h *Host) SetResultVar(varName, varValue string)
- func (h *Host) SubstituteResultVars(cmd string) string
- type Hosts
- type HostsCmd
- type LocalCmd
- type SSHCmd
- type UlCmd
- type UlDl
Constants ¶
const ( // ExecModeCmdByCmd means execute a command in all relative hosts and then continue to next command // eg. cmd1: host1,host2, cmd2:host1, host2 ExecModeCmdByCmd int = iota // ExecModeHostByHost means execute a host relative commands and the continue to next host. // eg .host1: cmd1,cmd2, host2:cmd1, cmd2 ExecModeHostByHost )
Variables ¶
var LocalHost = &Host{ID: "localhost", Addr: "localhost", resultVars: make(map[string]string)}
LocalHost means the local host.
Functions ¶
func DecryptPassphrase ¶
func DecryptPassphrase(passphrase string)
func ExecInHosts ¶
func ExecInHosts(gs *GoSSH, target *Host, hostsCmd HostsCmd, stdout io.Writer, eo ExecOption, hostGroup string) error
ExecInHosts execute in specified hosts.
func ExecuteInitialCmd ¶
ExecuteInitialCmd executes initial command.
func GetLastLine ¶
GetLastLine gets the last line of s.
func IsCapitalized ¶
IsCapitalized test a string is a capitalized one.
func StripAnsiBytes ¶
StripAnsi removes all ANSI Escape Sequences from the byteslice
Types ¶
type AnsiStripper ¶
type AnsiStripper struct {
// contains filtered or unexported fields
}
func NewStripAnsiWriter ¶
func NewStripAnsiWriter(w io.WriteCloser) *AnsiStripper
type CmdChanClosed ¶
type CmdChanClosed struct{}
CmdChanClosed represents the cmd channel closed event.
type CmdWrap ¶
type CmdWrap struct { Cmd string ResultVar string ExecOption }
CmdWrap wraps a command with result variable name.
type Config ¶
type Config struct { ReplaceQuote string `help:"replace for quote" short:"q"` ReplaceBang string `help:"replace for bang(!)" short:"b"` Separator string `help:"separator for hosts, cmds, default comma" short:"s"` NetTimeout string `help:"timeout(eg. 15s, 3m), empty for no timeout"` CmdTimeout string `help:"timeout(eg. 15s, 3m), default 15m"` Group string `help:"group name"` CmdsFile string `help:"cmds file"` HostsFile string `help:"hosts file" short:"f"` Pass string `help:"pass."` User string `help:"user" short:"u"` Passphrase string `help:"passphrase for decrypt {PBE}Password" short:"p"` Cmds []string `help:"commands to be executedChan" short:"C"` Hosts []string `help:"hosts" short:"H"` ExecMode int `help:"exec mode(0: cmd by cmd, 1 host by host)" short:"e"` FirstConfirm bool Confirm bool `help:"conform to continue."` // 是否全局设置为远程shell命令 GlobalRemote bool `help:"run as global remote ssh command(no need %host)" short:"g"` PrintConfig bool `help:"print config before running" short:"P"` SplitSSH bool `help:"split ssh commands by comma or not" short:"S"` }
Config represents the structure of input toml file structure.
type Host ¶
type Host struct { Properties map[string][]string Proxy *Host Password string // empty when using public key Addr string User string ID string // contains filtered or unexported fields }
Host represents the structure of remote host information for ssh.
func NewExecModeCmdByCmd ¶
func NewExecModeCmdByCmd() *Host
NewExecModeCmdByCmd creates an exec mode command.
func (*Host) GetGosshConnect ¶
GetGosshConnect get gossh Connect.
func (*Host) GetSftpClient ¶
GetSftpClient get sftClient by host.
func (*Host) IsConnected ¶
IsConnected tells if host is connected by ssh or sftp.
func (*Host) IsExecModeCmdByCmd ¶
IsExecModeCmdByCmd tests if this is mode of cmd one by one or not.
func (*Host) SSH ¶
SSH executes ssh commands on remote host h. http://networkbit.ch/golang-ssh-client/
func (*Host) SetResultVar ¶
SetResultVar sets the value of result variable.
func (*Host) SubstituteResultVars ¶
SubstituteResultVars substitutes the variables in the command line string.
type Hosts ¶
type Hosts []*Host
Hosts stands for slice of Host.
func (Hosts) FixHost ¶
func (hosts Hosts) FixHost()
FixHost fix the host ID by sequence if it is blank.
type HostsCmd ¶
type HostsCmd interface { // Exec execute in specified host. Exec(gs *GoSSH, host *Host, stdout io.Writer, eo ExecOption) error // TargetHosts returns target hosts for the command TargetHosts(hostGroup string) Hosts }
HostsCmd means the executable interface.
type LocalCmd ¶
type LocalCmd struct {
// contains filtered or unexported fields
}
LocalCmd means local commands.
func (LocalCmd) TargetHosts ¶
TargetHosts returns target hosts for the command.
type SSHCmd ¶
type SSHCmd struct {
// contains filtered or unexported fields
}
SSHCmd means SSH command.
func (*SSHCmd) TargetHosts ¶
TargetHosts returns target hosts for the command.