mirror of
https://github.com/appleboy/drone-ssh.git
synced 2026-06-14 05:12:39 +08:00
upgrade easyssh to 1.1.6 (#81)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
+56
-1
@@ -1,6 +1,11 @@
|
||||
# easyssh-proxy
|
||||
|
||||
[](https://godoc.org/github.com/appleboy/easyssh-proxy) [](http://drone.wu-boy.com/appleboy/easyssh-proxy) [](https://codecov.io/gh/appleboy/easyssh-proxy) [](https://goreportcard.com/report/github.com/appleboy/easyssh-proxy) [](https://sourcegraph.com/github.com/appleboy/easyssh-proxy?badge)
|
||||
[](https://godoc.org/github.com/appleboy/easyssh-proxy)
|
||||
[](http://drone.wu-boy.com/appleboy/easyssh-proxy)
|
||||
[](https://codecov.io/gh/appleboy/easyssh-proxy)
|
||||
[](https://goreportcard.com/report/github.com/appleboy/easyssh-proxy)
|
||||
[](https://sourcegraph.com/github.com/appleboy/easyssh-proxy?badge)
|
||||
[](https://github.com/appleboy/easyssh-proxy/releases/latest)
|
||||
|
||||
easyssh-proxy provides a simple implementation of some SSH protocol features in Go.
|
||||
|
||||
@@ -124,3 +129,53 @@ See [example/proxy/proxy.go](./example/proxy/proxy.go)
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### SSH Stream Log
|
||||
|
||||
See [example/stream/stream.go](./example/stream/stream.go)
|
||||
|
||||
[embedmd]:# (example/stream/stream.go go /func/ /^}$/)
|
||||
```go
|
||||
func main() {
|
||||
// Create MakeConfig instance with remote username, server address and path to private key.
|
||||
ssh := &easyssh.MakeConfig{
|
||||
Server: "localhost",
|
||||
User: "drone-scp",
|
||||
KeyPath: "./tests/.ssh/id_rsa",
|
||||
Port: "22",
|
||||
Timeout: 60 * time.Second,
|
||||
}
|
||||
|
||||
// Call Run method with command you want to run on remote server.
|
||||
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream("for i in {1..5}; do echo ${i}; sleep 1; done; exit 2;", 60)
|
||||
// Handle errors
|
||||
if err != nil {
|
||||
panic("Can't run remote command: " + err.Error())
|
||||
} else {
|
||||
// read from the output channel until the done signal is passed
|
||||
isTimeout := true
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case isTimeout = <-doneChan:
|
||||
break loop
|
||||
case outline := <-stdoutChan:
|
||||
fmt.Println("out:", outline)
|
||||
case errline := <-stderrChan:
|
||||
fmt.Println("err:", errline)
|
||||
case err = <-errChan:
|
||||
}
|
||||
}
|
||||
|
||||
// get exit code or command error.
|
||||
if err != nil {
|
||||
fmt.Println("err: " + err.Error())
|
||||
}
|
||||
|
||||
// command time out
|
||||
if !isTimeout {
|
||||
fmt.Println("Error: command timeout")
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user