command

package
v0.0.0-...-8664ab5 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumePassword

func ConsumePassword(username string, password string) (string, error)

ConsumePassword will prompt the user for a password, reads it from STDIN, and returns it.

func EstablishSFTPConnection

func EstablishSFTPConnection(sshClient *ssh.Client) (*sftp.Client, error)

EstablishSFTPConnection returns an sftp client for use

func EstablishSSHConnection

func EstablishSSHConnection(username string, password string, host string, ignoreHostKeyCheck bool, privateKey string) (*ssh.Client, error)

EstablishSSHConnection returns an ssh client config from an id_rsa or username/password

func TransferScript

func TransferScript(scriptPath string, client *sftp.Client) (string, error)

TransferScript copies a script to a remote host and sets its mode to 0777

Types

type Options

type Options struct {
	// Command that will be ran, if provided
	Command string
	// if true, delete the script after execution
	Cleanup bool
	// Whether or not to verify host keys
	IgnoreHostkeyCheck bool
	// Host to execute on
	Host string
	// User to execute as
	User string
	// Password for User
	Password string
	// A custom private key to use
	PrivateKey string
	// A script to be ran, if provided
	Script string
}

Options contains information on the the command to be ran

func (*Options) RunCommand

func (opts *Options) RunCommand() (Result, error)

RunCommand is a wrapper around establishing the ssh connection and then calling the RunSSHCommand

func (*Options) RunScript

func (opts *Options) RunScript() (Result, error)

RunScript is a wrapper around establishing an sftp connection, and running a script

type Result

type Result struct {
	// The command that was ran.
	CommandRan string `json:"command" yaml:"command"`
	// stdout from the command.
	Stdout string `json:"result" yaml:"result"`
	// Host command ran on
	Host string `json:"host" yaml:"host"`
}

Result contains various information about what a command returned.

func RunSSHCommand

func RunSSHCommand(command string, host string, session *ssh.Session) (Result, error)

RunSSHCommand runs the command and records its information in a CommandResult

func (*Result) PrintHostOutput

func (r *Result) PrintHostOutput(format string)

PrintHostOutput formats the host and stdout nicely.

Jump to

Keyboard shortcuts

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