diff --git a/mod_gearman_worker_testcmd.go b/mod_gearman_worker_testcmd.go index 92ee495..9ca8f1e 100644 --- a/mod_gearman_worker_testcmd.go +++ b/mod_gearman_worker_testcmd.go @@ -11,7 +11,7 @@ func runTestCmd(conf *configurationStruct, args []string) (rc int, output string typ: "service", hostName: "test check from commandline", serviceDescription: "test", - commandLine: strings.Join(args, " "), + commandLine: buildCommandLine(args), } if len(args) == 0 { return 3, "usage: mod_gearman_worker [--job_timeout=seconds] testcmd " @@ -32,3 +32,14 @@ func runTestCmd(conf *configurationStruct, args []string) (rc int, output string logger.Debugf("test cmd rc: %d\n", rc) return } + +// reconstruct command line from array of args +func buildCommandLine(args []string) string { + cmd := args[0] + for _, a := range args[1:] { + // escape quotes + a = strings.ReplaceAll(a, `"`, `\"`) + cmd = cmd + ` "` + a + `"` + } + return cmd +}