From ee3aad8a2f33e147f0cd001917ce31acbb9b37fd Mon Sep 17 00:00:00 2001 From: alse Date: Tue, 26 Nov 2019 21:55:45 -0800 Subject: [PATCH] Ability to view stdout added --- app.js | 20 +++++++++++++++----- crontab.js | 6 ++++++ routes.js | 1 + views/index.ejs | 3 ++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index fa63511..2e10b30 100755 --- a/app.js +++ b/app.js @@ -184,13 +184,23 @@ app.get(routes.import_crontab, function(req, res) { res.end(); }); -// get the log file a given job. id passed as query param -app.get(routes.logger, function(req, res) { - _file = crontab.log_folder +"/"+req.query.id+".log"; - if (fs.existsSync(_file)) - res.sendFile(_file); +function sendLog(path, req, res) { + if (fs.existsSync(path)) + res.sendFile(path); else res.end("No errors logged yet"); +} + +// get the log file a given job. id passed as query param +app.get(routes.logger, function(req, res) { + let _file = crontab.log_folder + "/" + req.query.id + ".log"; + sendLog(_file, req, res); +}); + +// get the log file a given job. id passed as query param +app.get(routes.stdout, function(req, res) { + let _file = crontab.log_folder + "/" + req.query.id + ".stdout.log"; + sendLog(_file, req, res); }); // error handler diff --git a/crontab.js b/crontab.js index 2d492fe..d5c941f 100644 --- a/crontab.js +++ b/crontab.js @@ -95,6 +95,7 @@ exports.set_crontab = function(env_vars, callback){ let stderr = path.join(cronPath, tab._id + ".stderr"); let stdout = path.join(cronPath, tab._id + ".stdout"); let log_file = path.join(exports.log_folder, tab._id + ".log"); + let log_file_stdout = path.join(exports.log_folder, tab._id + ".stdout.log"); if(tab.command[tab.command.length-1] != ";") // add semicolon tab.command +=";"; @@ -106,6 +107,11 @@ exports.set_crontab = function(env_vars, callback){ "; then date >> \"" + log_file + "\"" + "; cat " + stderr + " >> \"" + log_file + "\"" + "; fi"; + + crontab_string += "; if test -f " + stdout + + "; then date >> \"" + log_file_stdout + "\"" + + "; cat " + stdout + " >> \"" + log_file_stdout + "\"" + + "; fi"; } if (tab.hook) { diff --git a/routes.js b/routes.js index 210f79e..3770272 100644 --- a/routes.js +++ b/routes.js @@ -14,4 +14,5 @@ exports.routes = { "import": "/import", // this is import from database "import_crontab": "/import_crontab", // this is from existing crontab "logger": "/logger", + "stdout": "/stdout", }; diff --git a/views/index.ejs b/views/index.ejs index 565439b..d2f48dc 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -82,7 +82,8 @@ <% if (!crontab.stopped) { %> <% if (crontab.logging && crontab.logging != "false") {%> - + + <% } %> Run Edit