linux

package
v0.3.16 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 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"
	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 FindMountPoint added in v0.3.10

func FindMountPoint(path string) (string, error)

FindMountPoint returns the mount point of the given path, note that this function only works on unix-like system

func GetDefaultIP

func GetDefaultIP() (string, error)

GetDefaultIP gets the default non-local ip, if there are more than one ips, it will return the first one

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(dirName, rootPath string) (map[string]string, 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 server with given pid, it acts like shell command "kill -9", it will also remove pid file if pid file path is specified as opts

func MatchMountPoint added in v0.3.11

func MatchMountPoint(path string, mountPoints []string) (string, error)

MatchMountPoint matches mount point of given path in the mount point slice, if nothing matched, it returns "/" as default mount point

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 SendSignal added in v0.2.19

func SendSignal(pid int, sig syscall.Signal, opts ...string) (err error)

SendSignal sends signal to given pid, it will also remove pid file if pid file path is specified as opts

func ShutdownServer added in v0.2.19

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

ShutdownServer kills server with given pid, it acts like shell command "kill -15", it will also remove pid file if pid file path is specified as opts

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) *MyConn

func NewMyConnWithDefaultValue added in v0.1.4

func NewMyConnWithDefaultValue(hostIP string) *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{}) (*MySSHConn, 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() error

Close closes connections with the remote host

func (*MySSHConn) CopyDirFromRemote added in v0.1.4

func (conn *MySSHConn) CopyDirFromRemote(dirNameSource, dirNameDest string) 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) error

CopyDirToRemote 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) 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) 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) 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) 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)

CopyToRemote 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) (string, error)

ExecuteCommand executes shell command on the remote host

func (*MySSHConn) GetHostName added in v0.1.4

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

GetHostName returns hostname of remote host

func (*MySSHConn) GetPathDirMapRemote added in v0.1.5

func (conn *MySSHConn) GetPathDirMapRemote(dirName, rootPath string) (map[string]string, 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) (bool, 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) (bool, error)

IsEmptyDir returns if given directory is empty or not

func (*MySSHConn) ListPath added in v0.1.4

func (conn *MySSHConn) ListPath(path string) ([]string, 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) ([]os.FileInfo, 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) 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