[Excution] - base function accomplish - 4

This commit is contained in:
IceDerce
2023-06-26 13:50:14 +08:00
parent 80198930c4
commit 97187363cc
6 changed files with 88 additions and 30 deletions

View File

@@ -13,6 +13,7 @@ type ExecutionMessage struct {
NeedResultReplay bool `json:"needResultReplay"`
DurationTask bool `json:"durationTask,default:false"`
Type string `json:"type"`
BaseFuncContent []string `json:"baseFuncContent"`
SingleLineCommand []string `json:"singleLineCommand"`
MultiLineCommand [][]string `json:"multiLineCommand"`
PipeLineCommand [][]string `json:"pipeLineCommand"`
@@ -21,24 +22,35 @@ type ExecutionMessage struct {
var log = logger2.Log
var AgentOsOperatorCache = &AgentOsOperator{}
func Execute(em *ExecutionMessage) ([]string, error) {
var resultLog []string
var err error
var realCommand [][]string
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
// 管道命令
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
realCommand = em.PipeLineCommand
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
// 多行命令
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
realCommand = em.MultiLineCommand
if strings.HasPrefix(em.Type, "BASE") {
// base function
resultLog = AgentOsOperatorCache.Exec(em.BaseFuncContent[0], em.BaseFuncContent[1:]...)
err = nil
} else {
// 单行命令
resultLog, err = SingleLineCommandExecutor(em.SingleLineCommand)
realCommand = [][]string{em.SingleLineCommand}
// shell command
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
// 管道命令
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
realCommand = em.PipeLineCommand
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
// 多行命令
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
realCommand = em.MultiLineCommand
} else {
// 单行命令
resultLog, err = SingleLineCommandExecutor(em.SingleLineCommand)
realCommand = [][]string{em.SingleLineCommand}
}
}
// 归一化错误和日志