sshExecutor

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 13 Imported by: 0

README

ssh-executor

Lib for local/remote ssh operations.

  • connect
  • exec statements (also with sudo, also with parsing output)
  • send files through scp

import

import (
  sshExecutor "github.com/NGRsoftlab/ssh-executor"
)

examples

// exec "ls -la /home/myuser" command on remote "155.34.34.1"
out, _ := sshExecutor.GetSudoCommandsOutWithoutErr(
		sshExecutor.ConnectParams{
			Host:       "155.34.34.1",
			Port:       22,
			PrivateKey: MyConfig.SSHPrivateKey(), // MyConfig - smth like app configuration obj
		},
		time.Second * 30,
		time.Second * 30,
		"ls -la /home/myuser",
	)

// let's see command output
fmt.Println(out)

Documentation

Overview

Copyright © NGR Softlab 2020-2024

Copyright © NGR Softlab 2020-2024

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCommandOutWithErr

func GetCommandOutWithErr(connParams ConnectParams, kill chan *os.Signal,
	timeoutConn, timeoutCmd time.Duration, command string) (output []byte, errOutput []byte, duration time.Duration, err error)

GetCommandOutWithErr get result command output (with errOut) from ssh connection

func GetSudoCommandsOutWithoutErr

func GetSudoCommandsOutWithoutErr(connParams ConnectParams,
	timeoutConn, timeoutCmd time.Duration, commands ...string) (output []byte, err error)

GetSudoCommandsOutWithoutErr get result sudo (!) commands... output from ssh connection

func LocalExecContext

func LocalExecContext(timeout time.Duration, command string, params ...string) (output []byte, err error)

LocalExecContext local execution command with context

func SendFileWithScp

func SendFileWithScp(connParams ConnectParams, kill chan *os.Signal,
	timeoutConn, timeoutCmd time.Duration, pathParams FilePathParams) (time.Duration, error)

SendFileWithScp get result command output (with errOut) from ssh connection

Types

type ConnectParams

type ConnectParams struct {
	Host       string
	Port       int
	User       string
	Psw        string
	PrivateKey string
}

ConnectParams params for ssh connection

type Connection

type Connection struct {
	*ssh.Client
	// contains filtered or unexported fields
}

Connection ssh connection struct

func GetSshConnection

func GetSshConnection(connParams ConnectParams, timeout time.Duration) (connection *Connection, err error)

GetSshConnection getting ssh connection

func (*Connection) SendOneCommandWithErrOut

func (conn *Connection) SendOneCommandWithErrOut(kill chan *os.Signal, command string) ([]byte, []byte, time.Duration, error)

SendOneCommandWithErrOut sending one command (no SUDO, with strErr output, with killChan)

func (*Connection) SendScpFile

func (conn *Connection) SendScpFile(kill chan *os.Signal, pathParams FilePathParams) (time.Duration, error)

SendScpFile sending file (content = file string content) to rootFolder/folderName/fileName with scp

func (*Connection) SendSudoCommandsWithoutErrOut

func (conn *Connection) SendSudoCommandsWithoutErrOut(commands ...string) ([]byte, error)

SendSudoCommandsWithoutErrOut sending many commands (may be with SUDO, without strErr output)

func (*Connection) SendSudoPassword

func (conn *Connection) SendSudoPassword(in io.WriteCloser, out io.Reader, output *[]byte)

SendSudoPassword checking for sudo password ask (with recovery, be careful)

type FilePathParams

type FilePathParams struct {
	RootFolder   string
	FolderName   string
	FolderRights string
	FileName     string
	FileRights   string
	Content      string
}

FilePathParams params for scp file sending

Jump to

Keyboard shortcuts

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