{"id":1246,"date":"2016-11-18T11:36:48","date_gmt":"2016-11-18T11:36:48","guid":{"rendered":"http:\/\/10sa.com\/sql_stories\/?p=1246"},"modified":"2016-11-18T11:36:48","modified_gmt":"2016-11-18T11:36:48","slug":"how-to-log-errors-of-all-scripts-executed-via-cron-to-one-file","status":"publish","type":"post","link":"http:\/\/10sa.com\/sql_stories\/?p=1246","title":{"rendered":"How to log errors of all scripts executed via cron to one file?"},"content":{"rendered":"<p>To achieve such feature I prepared mix which is to be used in both script and cron<\/p>\n<p>The example:<\/p>\n<pre lang=bash>\r\ncrontab -l\r\n<span style=\"color:#dd2020\">CRON_ERR=\/var\/log\/overseer.log<\/span>\r\n* * * * * YourScript.sh <span style=\"color:#dd2020\">2>>$CRON_ERR || echo \"[`date`] YourScript.sh\" >>$CRON_ERR 2>&1<\/span>\r\n<\/pre>\n<p>As I have already mentioned you have to modify your script either<\/p>\n<pre lang=bash>\r\n#!\/bin\/bash\r\n<span style=\"color:#dd2020\">set -E\r\nGLOBAL_ERR=0\r\ntrap \"GLOBAL_ERR=127\" ERR<\/span>\r\n\r\n[... your instructions]\r\n\r\n<span style=\"color:#dd2020\">exit $GLOBAL_ERR<\/span>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To achieve such feature I prepared mix which is to be used in both script and cron The example: crontab -l CRON_ERR=\/var\/log\/overseer.log * * * * * YourScript.sh 2>>$CRON_ERR || echo &#8220;[`date`] YourScript.sh&#8221; >>$CRON_ERR 2>&#038;1 As I have already mentioned you have to modify your script either #!\/bin\/bash set -E GLOBAL_ERR=0 trap &#8220;GLOBAL_ERR=127&#8221; ERR [&#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[],"_links":{"self":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/1246"}],"collection":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1246"}],"version-history":[{"count":5,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/1246\/revisions"}],"predecessor-version":[{"id":1251,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/1246\/revisions\/1251"}],"wp:attachment":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1246"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}