linuxssh

package
v0.0.0-...-6e5b399 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package linuxssh provides Linux specific operations conducted via SSH

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFile

func GetFile(ctx context.Context, s *ssh.Conn, src, dst string, symlinkPolicy SymlinkPolicy) error

GetFile copies a file or directory from the host to the local machine. dst is the full destination name for the file or directory being copied, not a destination directory into which it will be copied. dst will be replaced if it already exists.

func GetFileTail

func GetFileTail(ctx context.Context, s *ssh.Conn, src, dst string, startLine, maxSize int64) error

GetFileTail reads the file on the path and returns the file truncate by command tail with the Max System Message Log Size and destination.

func PutFiles

func PutFiles(ctx context.Context, s *ssh.Conn, files map[string]string,
	symlinkPolicy SymlinkPolicy) (bytes int64, err error)

PutFiles copies files on the local machine to the host. files describes a mapping from a local file path to a remote file path. For example, the call:

PutFiles(ctx, conn, map[string]string{"/src/from": "/dst/to"})

will copy the local file or directory /src/from to /dst/to on the remote host. Local file paths can be absolute or relative. Remote file paths must be absolute. SHA1 hashes of remote files are checked in advance to send updated files only. bytes is the amount of data sent over the wire (possibly after compression).

func ReadFile

func ReadFile(ctx context.Context, conn *ssh.Conn, path string) ([]byte, error)

ReadFile reads the file on the path and returns the contents.

func WaitUntilFileExists

func WaitUntilFileExists(ctx context.Context, conn *ssh.Conn, path string, timeout, interval time.Duration) error

WaitUntilFileExists checks if a file exists on an interval until it either exists or the timeout is reached.

func WriteFile

func WriteFile(ctx context.Context, conn *ssh.Conn, path string, data []byte, perm os.FileMode) error

WriteFile writes data to the file on the path. If the file does not exist, WriteFile creates it with permissions perm; otherwise WriteFile truncates it before writing, without changing permissions. Unlike ioutil.WriteFile, it doesn't apply umask on perm.

Types

type RemoteFileDelta

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

RemoteFileDelta describes the result from the function NewRemoteFileDelta.

func NewRemoteFileDelta

func NewRemoteFileDelta(ctx context.Context, conn *ssh.Conn, src, dst string, maxSize int64) (*RemoteFileDelta, error)

NewRemoteFileDelta gets the starting line of from DUT and then save the source file, destintion file and the starting line to RemoteFileDelta which will be returned to the caller.

func (*RemoteFileDelta) Save

func (rtd *RemoteFileDelta) Save(ctx context.Context, conn *ssh.Conn) error

Save calls the GetFileTail with struct RemoteFileDelta. The range between beginning of the file and rtd.startline will be truncated.

type SymlinkPolicy

type SymlinkPolicy int

SymlinkPolicy describes how symbolic links should be handled by PutFiles.

const (
	// PreserveSymlinks indicates that symlinks should be preserved during the copy.
	PreserveSymlinks SymlinkPolicy = iota
	// DereferenceSymlinks indicates that symlinks should be dereferenced and turned into normal files.
	DereferenceSymlinks
)

type WordCountInfo

type WordCountInfo struct {
	Lines int64
	Words int64
	Bytes int64
}

WordCountInfo describes the result from the unix command wc.

func WordCount

func WordCount(ctx context.Context, conn *ssh.Conn, path string) (*WordCountInfo, error)

WordCount get the line, word and byte counts of a remote text file.

Jump to

Keyboard shortcuts

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