示例#1
0
func Example() {
	ssh := gossh.NewSsh()
	rsp, err := ssh.Run([]string{"localhost"}, "date", gossh.Options{})
	if err != nil {
		log.Fatalf("Unable to run command 'date' on host 'localhost': %v\n", err)
	}

	for ctx := range rsp.Responses {
		log.Printf("Response from host %s: %s\n", ctx.Hostname, ctx.Response.Stdout)
	}
}
示例#2
0
文件: main.go 项目: Civil/gossh
func main() {
	args, err := parseArgs()
	if err != nil {
		fmt.Printf("%s", err.Error())
		os.Exit(1)
	}
	ssh := gossh.NewSsh()
	hosts, err := utils.Expand(args.Hosts)
	if err != nil {
		panic(err)
	}
	rsp, err := ssh.Run(hosts, args.Cmd, args.Opts)
	if err != nil {
		panic(err)
	}
	for ctx := range rsp.Responses {
		log.Printf("Hostname: %s\nStdout: %s\nStderr: %s\n", ctx.Hostname, ctx.Response.Stdout, ctx.Response.Stderr)
	}
}