[ Agent ] [ Base ] - nfs-server nfs
This commit is contained in:
@@ -230,3 +230,41 @@ func collectOutput(r io.Reader, resultSlice []string) []string {
|
||||
|
||||
return resultSlice
|
||||
}
|
||||
|
||||
// HardCodeCommandExecutor 执行硬编码的shell命令,如 echo sda > sdasd ; rpcinfo -p localhost 等
|
||||
func HardCodeCommandExecutor(hardCodeCommand string) (bool, []string) {
|
||||
|
||||
// result
|
||||
var resultSlice []string
|
||||
resultOk := true
|
||||
|
||||
cmd := exec.Command("sh", "-c", hardCodeCommand)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
log.DebugF("hard code command %v stdout error => %s", hardCodeCommand, err)
|
||||
resultOk = false
|
||||
}
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
log.DebugF("hard code command %v stderr error => %s", hardCodeCommand, err)
|
||||
resultOk = false
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.DebugF("hard code command %v runtime error => %v", hardCodeCommand, err)
|
||||
resultOk = false
|
||||
}
|
||||
|
||||
// 收集错误或者
|
||||
resultSlice = collectOutput(stdout, resultSlice)
|
||||
resultSlice = collectOutput(stderr, resultSlice)
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
log.DebugF("hard code command %v result error => %v", hardCodeCommand, err)
|
||||
resultOk = false
|
||||
}
|
||||
|
||||
log.DebugF("hard code command of %v result are => %v", hardCodeCommand, resultSlice)
|
||||
|
||||
return resultOk, resultSlice
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user