| 45 | } |
| 46 | |
| 47 | function makeCommand(tab) { |
| 48 | const stderr = path.join(cronPath, `${tab._id}.stderr`); |
| 49 | const stdout = path.join(cronPath, `${tab._id}.stdout`); |
| 50 | const logFile = path.join(logFolder, `${tab._id}.log`); |
| 51 | const logFileStdout = path.join(logFolder, `${tab._id}.stdout.log`); |
| 52 | |
| 53 | let cmd = tab.command; |
| 54 | if (cmd[cmd.length - 1] !== ';') { |
| 55 | cmd += ';'; |
| 56 | } |
| 57 | |
| 58 | let result = `({ ${cmd} } | tee ${stdout})`; |
| 59 | result = `(${result} 3>&1 1>&2 2>&3 | tee ${stderr}) 3>&1 1>&2 2>&3`; |
| 60 | result = `(${result})`; |
| 61 | |
| 62 | if (tab.logging && tab.logging === 'true') { |
| 63 | result += `; if test -f ${stderr}; then date >> "${logFile}"; cat ${stderr} >> "${logFile}"; fi`; |
| 64 | result += `; if test -f ${stdout}; then date >> "${logFileStdout}"; cat ${stdout} >> "${logFileStdout}"; fi`; |
| 65 | } |
| 66 | |
| 67 | if (tab.hook) { |
| 68 | result += `; if test -f ${stdout}; then ${tab.hook} < ${stdout}; fi`; |
| 69 | } |
| 70 | |
| 71 | if (tab.mailing && JSON.stringify(tab.mailing) !== '{}') { |
| 72 | result += `; /usr/local/bin/node ${__dirname}/bin/crontab-ui-mailer.js ${tab._id} ${stdout} ${stderr}`; |
| 73 | } |
| 74 | |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | function addEnvVars(envVars, command) { |
| 79 | if (envVars) { |