linux

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 23 Imported by: 9

Documentation

Index

Constants

View Source
const (
	HostNameCommand         = "hostname"
	LsCommand               = "ls"
	DefaultEstimateLineSize = 1024
	MinStartPosition        = 0
)
View Source
const (
	DefaultSplitStr           = "\n"
	DefaultStringZeroValue    = ""
	DefaultSuccessReturnValue = 0
	DefaultFailedReturnValue  = 1
	DefaultSSHTimeout         = 10 * time.Second
	DefaultSSHPortNum         = 22
	DefaultSSHUserName        = "root"
	DefaultSSHUserPass        = "root"
	DefaultByteBufferSize     = 1024 * 1024 // 1MB
)

Variables

This section is empty.

Functions

func ExecuteCommand added in v0.1.4

func ExecuteCommand(command string) (output string, err error)

ExecuteCommand is an alias of ExecuteCommandAndWait

func ExecuteCommandAndWait added in v0.1.20

func ExecuteCommandAndWait(command string) (output string, err error)

ExecuteCommandAndWait executes shell command and wait for it to complete

func ExecuteCommandNoWait added in v0.1.20

func ExecuteCommandNoWait(command string) (output string, err error)

ExecuteCommandNoWait executes shell command and does not wait for it to complete

func GetDefaultIP

func GetDefaultIP() (ip string, err error)

GetDefaultIP get a default non local ip, err is not nil, ip return 127.0.0.1

func GetFileNameDest added in v0.1.4

func GetFileNameDest(fileNameSource, dirDest string) string

GetFileNameDest returns the destination file name

func GetPathDirMapLocal added in v0.1.5

func GetPathDirMapLocal(pathDirMap map[string]string, dirName, rootPath string) (err error)

GetPathDirMapLocal reads all subdirectories and files of given directory and calculate the relative path of rootPath, then map the absolute path of subdirectory names and file names as keys, relative paths as values to fileDirMap

func GetPidFromPidFile added in v0.1.17

func GetPidFromPidFile(pidFile string) (int, error)

GetPidFromPidFile reads pid file and returns pid

func HandleSignalsWithPidFile added in v0.1.15

func HandleSignalsWithPidFile(pidFile string)

HandleSignalsWithPidFile handles operating system signals

func IsDir added in v0.1.4

func IsDir(path string) (isDir bool, err error)

IsDir returns if given path is a directory or not

func IsEmptyDir added in v0.1.4

func IsEmptyDir(dirName string) (isEmpty bool, err error)

IsEmptyDir returns if given directory is empty or not

func IsRunningWithPid added in v0.1.15

func IsRunningWithPid(pid int) (bool, error)

IsRunningWithPid returns if given pid is running

func IsRunningWithPidFile added in v0.1.15

func IsRunningWithPidFile(pidFile string) (bool, error)

IsRunningWithPidFile returns if process of which pid was saved in given pid file is running

func KillServer added in v0.1.18

func KillServer(pid int, opts ...string) (err error)

KillServer kills process with given pid, it will also remove pid file if pid file path is specified as opts

func KillServerWithSignal added in v0.1.19

func KillServerWithSignal(pid, signal int, opts ...string) error

KillServerWithSignal kills process with given pid and signal, it will also remove pid file if pid file path is specified as opts, as this function accepts signal as argument, it is only worked on unix-like system

func PathExists added in v0.1.5

func PathExists(path string) (bool, error)

PathExists returns if given path exists

func Readdir added in v0.1.4

func Readdir(dirName string) (fileInfoList []os.FileInfo, err error)

ReadDir returns subdirectories and files of given directory on the remote host, it returns a slice of os.FileInfo

func RemovePidFile added in v0.1.19

func RemovePidFile(pidFile string) error

func SavePid added in v0.1.4

func SavePid(pid int, pidFile string, fileMode os.FileMode) error

SavePid saves pid to pid file with given file mode

func SyscallMode added in v0.1.4

func SyscallMode(fileMode os.FileMode) (fileModeSys uint32)

SyscallMode returns file mode which could be used at syscall

func TailN added in v0.1.4

func TailN(fileName string, n int) (lines []string, err error)

TailN try get the latest n line of the file.

Types

type MyConn added in v0.1.4

type MyConn struct {
	HostIp   string
	PortNum  int
	UserName string
	UserPass string
}

func NewMyConn added in v0.1.4

func NewMyConn(hostIP string, portNum int, userName string, userPass string) (conn *MyConn)

func NewMyConnWithDefaultValue added in v0.1.4

func NewMyConnWithDefaultValue(hostIP string) (conn *MyConn)

type MySSHConn added in v0.1.4

type MySSHConn struct {
	MyConn
	SSHClient *ssh.Client
	*sftp.Client
}

func NewMySSHConn added in v0.1.4

func NewMySSHConn(hostIP string, portNum int, userName, userPass string) (*MySSHConn, error)

NewMySSHConn returns *MySSHConn and error

func NewMySSHConnWithOptionalArgs added in v0.1.4

func NewMySSHConnWithOptionalArgs(hostIP string, in ...interface{}) (sshConn *MySSHConn, err error)

NewMySSHConnWithOptionalArgs returns *MySSHConn and error, first argument is mandatory which presents host ip, and the 3 flowing optional arguments which should be in exact order of port number, user name and user password

func (*MySSHConn) Close added in v0.1.4

func (conn *MySSHConn) Close() (err error)

Close closes connections with the remote host

func (*MySSHConn) CopyDirFromRemote added in v0.1.4

func (conn *MySSHConn) CopyDirFromRemote(dirNameSource, dirNameDest string) (err error)

CopyDirFromRemote copies a directory with all subdirectories and files from remote to local

func (*MySSHConn) CopyDirToRemote added in v0.1.4

func (conn *MySSHConn) CopyDirToRemote(dirNameSource, dirNameDest string) (err error)

CopyDirFromRemote copies a directory with all subdirectories and files from local to remote

func (*MySSHConn) CopyFile added in v0.1.4

func (conn *MySSHConn) CopyFile(fileSource io.Reader, fileDest io.Writer, bufferSize int) (err error)

CopyFile copy file content from source to destination, it doesn't care about which one is local or remote

func (*MySSHConn) CopyFileListFromRemote added in v0.1.4

func (conn *MySSHConn) CopyFileListFromRemote(fileListSource []string, FileDirDest string) (err error)

CopyFileListFromRemote copies given files from remote to local

func (*MySSHConn) CopyFileListFromRemoteWithNewName added in v0.1.4

func (conn *MySSHConn) CopyFileListFromRemoteWithNewName(fileListSource []string, FileListDest []string) (err error)

CopyFileListFromRemoteWithNewName copies file from remote to local, it copies file contents and rename files to given file names

func (*MySSHConn) CopyFromRemote added in v0.1.4

func (conn *MySSHConn) CopyFromRemote(pathSource, pathDest string) (err error)

CopyFromRemote copies no matter a directory or a file from remote to local

func (*MySSHConn) CopySingleFileFromRemote added in v0.1.4

func (conn *MySSHConn) CopySingleFileFromRemote(fileNameSource string, fileNameDest string) (err error)

CopySingleFileFromRemote copies one single file from remote to local

func (*MySSHConn) CopySingleFileToRemote added in v0.1.4

func (conn *MySSHConn) CopySingleFileToRemote(fileNameSource string, fileNameDest string) (err error)

CopySingleFileToRemote copies one single file from local to remote

func (*MySSHConn) CopyToRemote added in v0.1.4

func (conn *MySSHConn) CopyToRemote(pathSource, pathDest string) (err error)

CopyFromRemote copies no matter a directory or a file from local to remote

func (*MySSHConn) ExecuteCommand added in v0.1.4

func (conn *MySSHConn) ExecuteCommand(cmd string) (output string, err error)

ExecuteCommand executes shell command on the remote host

func (*MySSHConn) GetHostName added in v0.1.4

func (conn *MySSHConn) GetHostName() (hostName string, err error)

GetHostName returns hostname of remote host

func (*MySSHConn) GetPathDirMapRemote added in v0.1.5

func (conn *MySSHConn) GetPathDirMapRemote(fileDirMap map[string]string, dirName, rootPath string) (err error)

GetPathDirMapRemote reads all subdirectories and files of given directory on the remote host and calculate the relative path of rootPath, then map the absolute path of subdirectory names and file names as keys, relative paths as values to fileDirMap

func (*MySSHConn) IsDir added in v0.1.4

func (conn *MySSHConn) IsDir(path string) (isDir bool, err error)

IsDir returns if given path on the remote host is a directory or not

func (*MySSHConn) IsEmptyDir added in v0.1.4

func (conn *MySSHConn) IsEmptyDir(dirName string) (isEmpty bool, err error)

IsEmptyDir returns if given directory is empty or not

func (*MySSHConn) ListPath added in v0.1.4

func (conn *MySSHConn) ListPath(path string) (subPathList []string, err error)

ListPath returns subdirectories and files of given path on the remote host, it returns a slice of sub paths

func (*MySSHConn) PathExists added in v0.1.5

func (conn *MySSHConn) PathExists(path string) (bool, error)

PathExists returns if given path exists

func (*MySSHConn) ReadDir added in v0.1.4

func (conn *MySSHConn) ReadDir(dirName string) (fileInfoList []os.FileInfo, err error)

ReadDir returns subdirectories and files of given directory on the remote host, it returns a slice of os.FileInfo

func (*MySSHConn) RemoveAll added in v0.1.4

func (conn *MySSHConn) RemoveAll(path string) (err error)

RemoveAll removes given path on the remote host, it will act like shell command "rm -rf $path", except that it will raise an error when something goes wrong.

Jump to

Keyboard shortcuts

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