Support arguments in commands

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-03-13 23:39:35 +01:00
parent cc8160ec67
commit a25b7530f2
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -17,6 +17,16 @@ func init() {
return nil
}
var command []string
for _, arg := range r.Command {
tmp, err := formatMessage(arg, m, ruleDef, nil)
if err != nil {
return errors.Wrap(err, "execute command argument template")
}
command = append(command, tmp)
}
ctx, cancel := context.WithTimeout(context.Background(), cfg.CommandTimeout)
defer cancel()
@ -35,7 +45,7 @@ func init() {
return errors.Wrap(err, "encoding script input")
}
cmd := exec.CommandContext(ctx, r.Command[0], r.Command[1:]...)
cmd := exec.CommandContext(ctx, command[0], command[1:]...)
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
cmd.Stdin = stdin