GithubHelp home page GithubHelp logo

msg stdout has been dropped about vssh HOT 4 CLOSED

yahoo avatar yahoo commented on August 30, 2024
msg stdout has been dropped

from vssh.

Comments (4)

mehrdadrad avatar mehrdadrad commented on August 30, 2024

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.

kailuo99 avatar kailuo99 commented on August 30, 2024

it is not work!
My proxy server network is not very good. Could it be related to this? Is there any good solution?
Dingtalk_20200928191337

from vssh.

kailuo99 avatar kailuo99 commented on August 30, 2024

Why is there still this problem when the timeout is set to 60 seconds?

from vssh.

mehrdadrad avatar mehrdadrad commented on August 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.