-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (38 loc) · 997 Bytes
/
main.go
File metadata and controls
42 lines (38 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/xeitodevs/remote-executor/input"
"fmt"
"time"
"github.com/xeitodevs/remote-executor/transport/ssh"
"github.com/xeitodevs/remote-executor/engine"
"os"
"bufio"
"log"
)
func main() {
args := input.ParseArgs()
input.StdinChecker(os.Stdin)
hosts, err := input.ParseHosts(bufio.NewReader(os.Stdin))
if err != nil {
log.Fatal(err.Error())
}
delta := uint(len(hosts))
responses := make(chan string)
commandQueue := engine.NewCommandQueue(delta)
for worker := 1; worker <= args.MaxConcurrency; worker++ {
go engine.New().Run(commandQueue)
}
for id, host := range hosts {
commandQueue.Add(&engine.Command{
Value: args.Command,
CreatedOn: time.Now(),
Id: id,
ChannelResponse: responses,
TransportAdapter: ssh.New(host, args.User, args.PrivateKeyPath), // In this case, is SSH , but could be http ...
})
}
commandQueue.Close()
for i := 0; i < len(hosts); i++ {
fmt.Println(<-responses)
}
}