-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_command.go
More file actions
45 lines (39 loc) · 982 Bytes
/
run_command.go
File metadata and controls
45 lines (39 loc) · 982 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
43
44
45
package main
import (
"fmt"
"sync"
"time"
logger "github.com/sirupsen/logrus"
)
type RealCommand struct {
round int
total int
command *Command
pcap *Pcap
realJob *RealJob
g *sync.WaitGroup
}
func (r *RealCommand) String() string {
if r.command.Type == "shell" {
return fmt.Sprintf("%s [%d/%d] %s", r.realJob, r.round, r.total, r.command)
} else {
return fmt.Sprintf("%s [%d/%d] %s %s", r.realJob, r.round, r.total, r.command, r.pcap)
}
}
func (r *RealCommand) run() {
logger.Infoln(fmt.Sprintf("%s executing", r))
start := time.Now()
result := execRealCommand(r)
end := time.Now()
duration := end.Sub(start)
if !result.succeed {
err := result.err.Error()
reason := result.output
if reason == "" {
reason = "<empty output>"
}
logger.Errorln(fmt.Sprintf("%s execute failed, use: %s, err is: %s, output is:\n%s\n", r, duration, err, reason))
} else {
logger.Infoln(fmt.Sprintf("%s execute succeed, use: %s", r, duration))
}
}