diff --git a/inputs/exec/exec.go b/inputs/exec/exec.go index d9e2430a..c8b2925d 100644 --- a/inputs/exec/exec.go +++ b/inputs/exec/exec.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log" + "os" osExec "os/exec" "path/filepath" "runtime" @@ -29,6 +30,8 @@ const MaxStderrBytes int = 512 type Instance struct { config.InstanceConfig + Scripts map[string]string `toml:"scripts"` + Commands []string `toml:"commands"` Timeout config.Duration `toml:"timeout"` DataFormat string `toml:"data_format"` @@ -63,6 +66,20 @@ func (e *Exec) GetInstances() []inputs.Instance { } func (ins *Instance) Init() error { + if len(ins.Scripts) > 0 { + for script, content := range ins.Scripts { + dir := filepath.Dir(script) + file := filepath.Base(script) + err := os.MkdirAll(dir, 0755) + if err != nil { + return err + } + err = os.WriteFile(filepath.Join(dir, file), []byte(content), 0755) + if err != nil { + return fmt.Errorf("write script %s error: %s", script, err) + } + } + } if len(ins.Commands) == 0 { return types.ErrInstancesEmpty }