Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specifying multiple hosts #19

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions util/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"net/http"
"regexp"
"strings"
"sync"
"time"

"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -178,19 +177,16 @@ func ParseQuery(w http.ResponseWriter, r *http.Request) (*regexp.Regexp, error)
//
func BatchExecute(c *Config, p *regexp.Regexp) (Config, error) {

var done sync.WaitGroup
t := make(chan bool)

for i, v := range c.Scripts {
if p.MatchString(v.Name) != true {
c.Scripts[i].Ignored = true
} else {
go executeScript(v.Script, v.Pattern, &c.Scripts[i].Credentials, &done, t)
go executeScript(v.Script, v.Pattern, &c.Scripts[i].Credentials, t)
}
}

done.Wait()

for _, v := range c.Scripts {
if !v.Ignored {
for _, _ = range v.Credentials {
Expand Down Expand Up @@ -271,13 +267,13 @@ func adjustConfig(c Config) (Config, error) {
//
// TLDR executeScript runs the given script in parallel on all hosts.
//
func executeScript(script, pattern string, creds *[]CredentialConfig, done *sync.WaitGroup, t chan bool) {
func executeScript(script, pattern string, creds *[]CredentialConfig, t chan bool) {

match, _ := regexp.Compile(pattern)

for i, c := range *creds {
done.Add(1)
go func() {
for ri, rc := range *creds {
go func(i int, c CredentialConfig) {

result, status, err := executeScriptOnHost(c.Host, c.Port, c.User, c.KeyFile, script)

(*creds)[i].ScriptReturnCode = status
Expand All @@ -294,9 +290,7 @@ func executeScript(script, pattern string, creds *[]CredentialConfig, done *sync
}

t <- true

done.Done()
}()
}(ri, rc)
}
}

Expand Down