sshclient

package
v0.0.0-...-2fa181f Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

SSH Client can login to multiple devices.

Example (ExecCommandsAdvaned)
// List of initial commands that dont need any outputs
initcmd := []string{
	"set cli op-command-xml-output on",
}

// List of the commands should be sent to the devices
listCMDs := []string{
	"test routing fib-lookup virtual-router default ip 1.1.1.1",
	"show interface ethernet1/1 | match zone",
	"exit",
}

sshconfig := InsecureClientConfig("admin", "admin", 5*time.Second)

rhc := CreateRhConfig("192.168.1.1", "tcp", "22")

result, err := ExecCommandsAdvaned(rhc, initcmd, listCMDs, sshconfig)
if err != nil {
	log.Fatal(err)
}

for _, item := range result {
	fmt.Println(item.Cmd)
	fmt.Println(item.Result)
}
Output:

Example (ExecCommandsSimple)
// List of initial commands that dont need any outputs
initcmd := "set cli op-command-xml-output on"

sshconfig := InsecureClientConfig("admin", "admin", 5*time.Second)

rhc := CreateRhConfig("192.168.1.1", "tcp", "22")

result, err := ExecCommandsSimple(rhc, listCMDs, sshconfig)
if err != nil {
	log.Fatal(err)
}

fmt.Println(result)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecSimple

func ExecSimple(rhc RhConfig, cmds []string, sshconfig *ssh.ClientConfig) (string, error)

ExecSimple uses ssh.Dial to dials to remote-host, applies commands mentioned in 'cmds'. This function needs remote-host IP, protocol and port which gets from RhConfig and also ssh.ClientConfig It returns a string as result

func InsecureClientConfig

func InsecureClientConfig(userStr, passStr string, t time.Duration) *ssh.ClientConfig

InsecureClientConfig ...

Types

type CmdResults

type CmdResults struct {
	Cmd    string
	Result string
}

CmdResults ... Command Result

func ExecAdvanced

func ExecAdvanced(rhc RhConfig, initcmds, cmds []string, sshconfig *ssh.ClientConfig) ([]CmdResults, error)

ExecAdvanced uses ssh.Dial to dials to remote-host, applies what is mentioned in 'initcmds' as initial commands, then 'cmds' as commands. This function needs remote-host IP, protocol and port which gets from RhConfig and also ssh.ClientConfig It returns a CmdResults

type RhConfig

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

RhConfig remote-host config

func CreateRhConfig

func CreateRhConfig(rh, protocol, port string) RhConfig

CreateRhConfig ... Create Remote-Host Config

Jump to

Keyboard shortcuts

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