host

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	net.Conn
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Conn wraps a net.Conn, and sets a deadline for every read and write operation.

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Implementation of io.Reader with timeout.

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Implementation of io.Writer.

type Host

type Host struct {
	IP           string
	Port         string
	Username     string
	Password     string
	Succeed      bool
	Result       string
	Stdout       string
	Stderr       string
	ExecDuration time.Duration
	Error        string
}

func LoadGob

func LoadGob() ([]*Host, error)

LoadGob read the gob file /tmp/carrier_log and deserialize it to []*Host.

type Hosts

type Hosts struct {
	HostSlice []*Host
	HostCh    chan *Host
}

func GetHosts

func GetHosts(fileName string) (*Hosts, error)

GetHosts read the csv file and parse it's content to []*Host then init a *Hosts. Empty lines and lines starts with '#' will be ignored. The first column is remote ip, the second column is ssh port, the third column is ssh username(default is root), the forth column is password. The csv file must has at least the first column, then the default value of port and username will be 22 and root.

func (*Hosts) ExecuteSCP

func (hosts *Hosts) ExecuteSCP(cfg *config.Config, src, dst, mask string) error

ExecuteSCP concurrently copy file/directory to remote hosts.

func (*Hosts) ExecuteSSH

func (hosts *Hosts) ExecuteSSH(cfg *config.Config, cmd string)

ExecuteSSH concurrently execute ssh command on remote hosts and print result.

func (Hosts) PrintResult

func (hosts Hosts) PrintResult()

PrintResult fetch the executed hosts from channel and print their results. The results will be printed immediately after execution.

func (*Hosts) SaveGob

func (hs *Hosts) SaveGob() error

SaveGob serialize the result of the last execution to a gob file and save it in /tmp/carrier_log.

Jump to

Keyboard shortcuts

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