sshcommand

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2015 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Host                string
	Port                int
	User                string
	SkipHostKeyChecking bool
	Quiet               bool
	SSHOptions          []string
	Gateway             *Command
	AllocateTTY         bool
	Command             []string
	Debug               bool
	NoEscapeCommand     bool
	// contains filtered or unexported fields
}

Command contains settings to build a ssh command

Example
return &Command{
	Host: "1.2.3.4",
}
Output:

Example (Complex)
return &Command{
	SkipHostKeyChecking: true,
	Host:                "1.2.3.4",
	Quiet:               true,
	AllocateTTY:         true,
	Command:             []string{"echo", "hello world"},
	Gateway: &Command{
		Host:        "5.6.7.8",
		User:        "toor",
		Quiet:       true,
		AllocateTTY: true,
	},
}
Output:

Example (Gateway)
return &Command{
	Host:    "1.2.3.4",
	Gateway: New("5.6.7.8"),
}
Output:

Example (Options)
return &Command{
	SkipHostKeyChecking: true,
	Host:                "1.2.3.4",
	Quiet:               true,
	AllocateTTY:         true,
	Command:             []string{"echo", "hello world"},
	Debug:               true,
}
Output:

func New

func New(host string) *Command

New returns a minimal Command

func (*Command) Slice

func (c *Command) Slice() []string

Slice returns an execve compatible slice of arguments

Example
fmt.Println(New("1.2.3.4").Slice())
Output:

[ssh 1.2.3.4]
Example (Complex)
command := Command{
	SkipHostKeyChecking: true,
	Host:                "1.2.3.4",
	Quiet:               true,
	AllocateTTY:         true,
	Command:             []string{"echo", "hello world"},
	NoEscapeCommand:     true,
	Gateway: &Command{
		SkipHostKeyChecking: true,
		Host:                "5.6.7.8",
		User:                "toor",
		Quiet:               true,
		AllocateTTY:         true,
	},
}
fmt.Printf("%q\n", command.Slice())
Output:

["ssh" "-q" "-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no" "-o" "ProxyCommand=ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -W %h:%p -l toor 5.6.7.8 -t -t" "1.2.3.4" "-t" "-t" "--" "/bin/sh" "-e" "-c" "\"echo hello world\""]
Example (Gateway)
command := Command{
	Host:    "1.2.3.4",
	Gateway: New("5.6.7.8"),
}
fmt.Printf("%q\n", command.Slice())
Output:

["ssh" "-o" "ProxyCommand=ssh -W %h:%p 5.6.7.8" "1.2.3.4"]
Example (Options)
command := Command{
	SkipHostKeyChecking: true,
	Host:                "1.2.3.4",
	Quiet:               true,
	AllocateTTY:         true,
	Command:             []string{"echo", "hello world"},
	Debug:               true,
	User:                "root",
}
fmt.Printf("%q\n", command.Slice())
Output:

["ssh" "-q" "-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no" "-l" "root" "1.2.3.4" "-t" "-t" "--" "/bin/sh" "-e" "-x" "-c" "\"\\\"echo\\\" \\\"hello world\\\"\""]
Example (User)
fmt.Println(New("root@1.2.3.4").Slice())
Output:

[ssh -l root 1.2.3.4]

func (*Command) String

func (c *Command) String() string

String returns a copy-pasteable command, useful for debugging

Example
fmt.Println(New("1.2.3.4").String())
Output:

ssh 1.2.3.4
Example (Complex)
command := Command{
	SkipHostKeyChecking: true,
	Host:                "1.2.3.4",
	Quiet:               true,
	AllocateTTY:         true,
	Command:             []string{"echo", "hello world"},
	Gateway: &Command{
		SkipHostKeyChecking: true,
		Host:                "5.6.7.8",
		User:                "toor",
		Quiet:               true,
		AllocateTTY:         true,
	},
}
fmt.Println(command.String())
Output:

ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o "ProxyCommand=ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -W %h:%p -l toor 5.6.7.8 -t -t" 1.2.3.4 -t -t -- /bin/sh -e -c "\"\\\"echo\\\" \\\"hello world\\\"\""
Example (Options)
command := Command{
	SkipHostKeyChecking: true,
	Host:                "1.2.3.4",
	Quiet:               true,
	AllocateTTY:         true,
	Command:             []string{"echo", "hello world"},
	Debug:               true,
}
fmt.Println(command.String())
Output:

ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 1.2.3.4 -t -t -- /bin/sh -e -x -c "\"\\\"echo\\\" \\\"hello world\\\"\""

Jump to

Keyboard shortcuts

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