-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (61 loc) · 1.28 KB
/
main.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"io/ioutil"
"log"
"os/exec"
"sync"
yaml "gopkg.in/yaml.v2"
)
type Configuration struct {
WebServers
}
type WebServers struct {
Hosts map[string]Server `yaml:"hosts"`
Tasks []Task
}
type Server struct {
Address string `yaml:"address"`
User string `yaml:"user"`
Dir string `yaml:"dir"`
}
type Task struct {
Name string `yaml:"name"`
Cmd string `yaml:"cmd"`
Args []string `yaml:"args"`
}
func (c *Configuration) getConf() *Configuration {
yamlFile, err1 := ioutil.ReadFile("config.yml")
if err1 != nil {
log.Printf("yamlFile.Get err #%v ", err1)
}
err2 := yaml.Unmarshal(yamlFile, &c)
if err2 != nil {
log.Fatalf("error: %v", err2)
}
return c
}
func Connection(s Server) {
cmd := exec.Command(
"ssh",
"-t",
fmt.Sprintf("%s@%s", s.User, s.Address),
fmt.Sprintf("'cd %s ; ls -al'", s.Dir),
)
stdout, err := cmd.Output()
if err != nil {
println(err.Error())
return
}
print(string(stdout))
}
func main() {
c := Configuration{}
c.getConf()
var wg sync.WaitGroup
for _, server := range c.WebServers.Hosts {
wg.Add(1)
go Connection(server)
}
wg.Wait()
}