[ Agent ] [ Base ] - nfs-server nfs

This commit is contained in:
zeaslity
2023-11-21 17:13:31 +08:00
parent 48e8a6c951
commit 55d0772d50
5 changed files with 191 additions and 6 deletions

View File

@@ -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
}