Comments (4)
It could happen at streaming, when stdout doesn't scan/read on time.
I suggest you to read the stdout like below right after executing a command.
Please let me know if you still has issue (w/ a sample code)
for stream.ScanStdout() {
txt := stream.TextStdout()
fmt.Println(txt)
}
from vssh.
it is not work!
My proxy server network is not very good. Could it be related to this? Is there any good solution?
from vssh.
Why is there still this problem when the timeout is set to 60 seconds?
from vssh.
when you run a command on multiple hosts, you get multiple responses at the same time.
here's an example to handle multiple responses.
func main() {
var wg sync.WaitGroup
vs := vssh.New().Start()
config, err := vssh.GetConfigPEM("ubuntu", "myaws.pem")
if err != nil {
log.Fatal(err)
}
for _, addr := range []string{"3.101.78.17:22", "13.57.12.15:22"} {
vs.AddClient(addr, config, vssh.SetMaxSessions(4))
}
vs.Wait()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cmd := "uname -a"
timeout, _ := time.ParseDuration("6s")
respChan := vs.Run(ctx, cmd, timeout)
for resp := range respChan {
if err := resp.Err(); err != nil {
log.Println("error", err)
continue
}
wg.Add(1)
go func(resp *vssh.Response) {
defer wg.Done()
handler(resp)
}(resp)
}
wg.Wait()
}
func handler(resp *vssh.Response) {
stream := resp.GetStream()
defer stream.Close()
for stream.ScanStdout() {
txt := stream.TextStdout()
fmt.Println(txt)
}
if err := stream.Err(); err != nil {
log.Println("error", err)
}
fmt.Println("host", resp.ID())
fmt.Println("exit code", resp.ExitStatus())
}
from vssh.
Related Issues (12)
- Bogus example in comment/README.md HOT 1
- Race condition HOT 1
- does it supports for batch upload files HOT 2
- how to use exist ssh client?
- Provide direct access to ssh.Session.StdoutPipe
- SetInitNumProc compile error HOT 1
- Run multiple commands in one SSH session
- Source ip/host? HOT 1
- Race conditions HOT 1
- Empty resp.ID() HOT 1
- Feature: feed private key from memory HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vssh.