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",
}
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,
},
}
Example (Gateway) ¶
return &Command{
Host: "1.2.3.4",
Gateway: New("5.6.7.8"),
}
Example (Options) ¶
return &Command{
SkipHostKeyChecking: true,
Host: "1.2.3.4",
Quiet: true,
AllocateTTY: true,
Command: []string{"echo", "hello world"},
Debug: true,
}
func (*Command) Slice ¶
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 ¶
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\\\"\""
Click to show internal directories.
Click to hide internal directories.