ssh

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

README

执行远程命令

执行远程ssh命令标准库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitSSHReady

func WaitSSHReady(ssh Interface, tryTimes int, hosts ...string) error

Types

type Client

type Client struct {
	SSH  Interface
	Host string
}

type Exec

type Exec struct {
	// contains filtered or unexported fields
}

func NewExecCmdFromIPs

func NewExecCmdFromIPs(vm *v1.VirtualMachine, ips []string) (*Exec, error)

func (*Exec) RunCmd

func (e *Exec) RunCmd(cmd string) error

func (*Exec) RunCopy

func (e *Exec) RunCopy(srcFilePath, dstFilePath string) error

type Interface

type Interface interface {
	// Copy is copy local files to remote host
	// scp -r /tmp root@192.168.0.2:/root/tmp => Copy("192.168.0.2","tmp","/root/tmp")
	// need check md5sum
	Copy(host, srcFilePath, dstFilePath string) error
	// CmdAsync is exec command on remote host, and asynchronous return logs
	CmdAsync(host string, cmd ...string) error
	// Cmd is exec command on remote host, and return combined standard output and standard error
	Cmd(host, cmd string) ([]byte, error)
	//CmdToString is exec command on remote host, and return spilt standard output and standard error
	CmdToString(host, cmd, spilt string) (string, error)
	Ping(host string) error
}

func NewSSHClient

func NewSSHClient(ssh *v1.SSH, isStdout bool) Interface

type SSH

type SSH struct {
	User         string
	Password     string
	PkFile       string
	PkData       string
	PkPassword   string
	Timeout      *time.Duration
	LocalAddress *[]net.Addr
	// contains filtered or unexported fields
}

func (*SSH) Cmd

func (s *SSH) Cmd(host, cmd string) ([]byte, error)

func (*SSH) CmdAsync

func (s *SSH) CmdAsync(host string, cmds ...string) error

func (*SSH) CmdToString

func (s *SSH) CmdToString(host, cmd, spilt string) (string, error)

CmdToString is in host exec cmd and replace to spilt str

func (*SSH) Connect

func (s *SSH) Connect(host string) (*ssh.Client, *ssh.Session, error)

func (*SSH) Copy

func (s *SSH) Copy(host, localPath, remotePath string) error

Copy is copy file or dir to remotePath, add md5 validate

func (*SSH) Ping

func (s *SSH) Ping(host string) error

func (*SSH) RemoteSha256Sum

func (s *SSH) RemoteSha256Sum(host, remoteFilePath string) string

Jump to

Keyboard shortcuts

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