Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-05-10 21:14:54 +08:00
parent 5f511f0399
commit 5af042b309
No known key found for this signature in database
GPG Key ID: 0F84B2110C500B1F

View File

@ -40,7 +40,7 @@ type (
) )
func (p Plugin) log(host string, message ...interface{}) { func (p Plugin) log(host string, message ...interface{}) {
if len(host) == 0 { if count := len(p.Config.Host); count == 1 {
fmt.Printf("%s", fmt.Sprintln(message...)) fmt.Printf("%s", fmt.Sprintln(message...))
} else { } else {
fmt.Printf("%s: %s", host, fmt.Sprintln(message...)) fmt.Printf("%s: %s", host, fmt.Sprintln(message...))
@ -65,9 +65,8 @@ func (p Plugin) Exec() error {
wg.Add(len(p.Config.Host)) wg.Add(len(p.Config.Host))
errChannel := make(chan error, 1) errChannel := make(chan error, 1)
finished := make(chan bool, 1) finished := make(chan bool, 1)
countHosts := len(p.Config.Host)
for _, host := range p.Config.Host { for _, host := range p.Config.Host {
go func(host string, counts int) { go func(host string) {
// Create MakeConfig instance with remote username, server address and path to private key. // Create MakeConfig instance with remote username, server address and path to private key.
ssh := &easyssh.MakeConfig{ ssh := &easyssh.MakeConfig{
Server: host, Server: host,
@ -96,10 +95,6 @@ func (p Plugin) Exec() error {
// read from the output channel until the done signal is passed // read from the output channel until the done signal is passed
stillGoing := true stillGoing := true
isTimeout := true isTimeout := true
// hide host in log if only single host in config.
if counts == 1 {
host = ""
}
for stillGoing { for stillGoing {
select { select {
case isTimeout = <-doneChan: case isTimeout = <-doneChan:
@ -124,7 +119,7 @@ func (p Plugin) Exec() error {
} }
wg.Done() wg.Done()
}(host, countHosts) }(host)
} }
go func() { go func() {