Documentation ¶
Index ¶
- Constants
- Variables
- func ExecInHosts(gs *GoSSH, target *Host, hostsCmd HostsCmd, stdout io.Writer) error
- func GetLastLine(s string) (preLines, curLine string)
- func IsCapitalized(str string) bool
- func StripAnsi(str string) string
- type CmdChanClosed
- type CmdExcResult
- type CmdWrap
- type Config
- type DlCmd
- type EchoState
- 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) PrintSCP()
- func (h *Host) PrintSSH()
- func (h *Host) Prop(name string) string
- func (h *Host) SSH(cmds []string, resultVar string, stdout io.Writer) 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. nolint:gochecknoglobals
Functions ¶
func ExecInHosts ¶ added in v1.0.0
ExecInHosts execute in specified hosts.
func GetLastLine ¶ added in v1.0.0
GetLastLine gets the last line of s.
func IsCapitalized ¶ added in v1.0.1
IsCapitalized test a string is a capitalized one.
Types ¶
type CmdChanClosed ¶ added in v1.0.0
type CmdChanClosed struct{}
CmdChanClosed represents the cmd channel closed event.
type Config ¶
type Config struct { ReplaceQuote string `pflag:"replace for quote(\"). shorthand=q"` ReplaceBang string `pflag:"replace for bang(!). shorthand=b"` Separator string `pflag:"separator for hosts, cmds, default comma. shorthand=s"` NetTimeout string `pflag:"timeout(eg. 15s, 3m), empty for no timeout."` CmdTimeout string `pflag:"timeout(eg. 15s, 3m), default 15m."` SplitSSH bool `pflag:"split ssh commands by comma or not. shorthand=S"` PrintConfig bool `pflag:"print config before running. shorthand=P"` // 是否全局设置为远程shell命令 GlobalRemote bool `pflag:"run as global remote ssh command(no need %host). shorthand=g"` Confirm bool `pflag:"conform to continue."` FirstConfirm bool Passphrase string `pflag:"passphrase for decrypt {PBE}Password. shorthand=p"` Hosts []string `pflag:"hosts. shorthand=H"` Cmds []string `pflag:"commands to be executedChan. shorthand=C"` User string `pflag:"user. shorthand=u"` Pass string `pflag:"pass."` HostsFile string `pflag:"hosts file. shorthand=f"` CmdsFile string `pflag:"cmds file."` ExecMode int `pflag:"exec mode(0: cmd by cmd, 1 host by host). shorthand=e"` }
Config represents the structure of input toml file structure.
func (Config) GetSeparator ¶ added in v1.0.0
GetSeparator get the separator.
type Host ¶
type Host struct { ID string Addr string User string Password string // empty when using public key Properties map[string]string Proxy *Host // contains filtered or unexported fields }
Host represents the structure of remote host information for ssh.
func (*Host) GetGosshConnect ¶ added in v1.0.0
GetGosshConnect get gossh Connect.
func (*Host) GetSftpClient ¶ added in v1.0.0
GetSftpClient get sftClient by host.
func (*Host) IsConnected ¶ added in v1.0.1
IsConnected tells if host is connected by ssh or sftp.
func (Host) PrintSCP ¶ added in v1.0.0
func (h Host) PrintSCP()
PrintSCP prints sshpass scp commands.
func (*Host) PrintSSH ¶ added in v1.0.0
func (h *Host) PrintSSH()
PrintSSH prints sshpass ssh commands.
func (*Host) SSH ¶ added in v1.0.0
SSH executes ssh commands on remote host h. http://networkbit.ch/golang-ssh-client/
func (*Host) SetResultVar ¶ added in v1.0.1
SetResultVar sets the value of result variable.
func (*Host) SubstituteResultVars ¶ added in v1.0.1
SubstituteResultVars substitutes the variables in the command line string.
type Hosts ¶ added in v1.0.0
type Hosts []*Host
Hosts stands for slice of Host.
func (Hosts) FixHostID ¶ added in v1.0.0
func (hosts Hosts) FixHostID()
FixHostID fix the host ID by sequence if it is blank.
type HostsCmd ¶ added in v1.0.0
type HostsCmd interface { // Parse parses the command. Parse() // Exec execute in specified host. Exec(gs *GoSSH, host *Host, stdout io.Writer) error // TargetHosts returns target hosts for the command TargetHosts() Hosts }
HostsCmd means the executable interface.
type LocalCmd ¶
type LocalCmd struct {
// contains filtered or unexported fields
}
LocalCmd means local commands.
func (LocalCmd) TargetHosts ¶ added in v1.0.0
TargetHosts returns target hosts for the command.
type SSHCmd ¶
type SSHCmd struct {
// contains filtered or unexported fields
}
SSHCmd means SSH command.
func (*SSHCmd) TargetHosts ¶ added in v1.0.0
TargetHosts returns target hosts for the command.
type UlCmd ¶ added in v0.2.0
type UlCmd struct { UlDl // contains filtered or unexported fields }
UlCmd upload cmd structure.
type UlDl ¶ added in v0.2.0
type UlDl struct {
// contains filtered or unexported fields
}
UlDl scp...
func (*UlDl) TargetHosts ¶ added in v1.0.0
TargetHosts returns target hosts for the command.