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 User string Port int SSHOptions []string Gateway *Command Command []string Debug bool NoEscapeCommand bool SkipHostKeyChecking bool Quiet bool AllocateTTY bool // contains filtered or unexported fields }
Command contains settings to build a ssh command
Example ¶
cmd := Command{ Host: "1.2.3.4", } // Do stuff fmt.Println(cmd)
Output:
Example (Complex) ¶
cmd := 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, }, } // Do stuff fmt.Println(cmd)
Output:
Example (Gateway) ¶
cmd := Command{ Host: "1.2.3.4", Gateway: New("5.6.7.8"), } // Do stuff fmt.Println(cmd)
Output:
Example (Options) ¶
cmd := Command{ SkipHostKeyChecking: true, Host: "1.2.3.4", Quiet: true, AllocateTTY: true, Command: []string{"echo", "hello world"}, Debug: true, } // Do stuff fmt.Println(cmd)
Output:
func New ¶
New returns a minimal Command
Example ¶
cmd := New("1.2.3.4") // Do stuff fmt.Println(cmd)
Output:
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 -p 22]
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 -p 22" "1.2.3.4" "-t" "-t" "-p" "22" "--" "/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 -p 22" "1.2.3.4" "-p" "22"]
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" "-p" "22" "--" "/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 -p 22]
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 -p 22
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 -p 22" 1.2.3.4 -t -t -p 22 -- /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 -p 22 -- /bin/sh -e -x -c "\"\\\"echo\\\" \\\"hello world\\\"\""
Click to show internal directories.
Click to hide internal directories.