{"id":157,"date":"2016-01-30T04:23:56","date_gmt":"2016-01-30T03:23:56","guid":{"rendered":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=157"},"modified":"2016-11-27T00:48:24","modified_gmt":"2016-11-26T23:48:24","slug":"mail-from-systemd-timers","status":"publish","type":"post","link":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=157","title":{"rendered":"Mail from systemd-timers"},"content":{"rendered":"<p>If you want to mail the output of a systemd-timer unit by redirecting STDOUT to \/usr\/bin\/mail or something: forget it. For a long time SysAdmin used to good old crond it definitely doesn&#8217;t work as expected. As long as you redirect STDOUT in your script or program, you won&#8217;t get any output, because systemd redirects STDOUT to the journal by default. It&#8217;s documented behavior, you just have to read the fine print in man systemd.exec (StandardOutput=).<\/p>\n<p>It&#8217;s rather counter-intuitive and has been discussed on systemd-devel, but in the end it&#8217;s &#8220;the right thing&#8221; \u00ae to do. Systemd PID 1 should not care nor can it know where STDOUT is currently connected to.<\/p>\n<p>So, how to work around it? Most likely your timer-thingy is a script wrapped in a service unit with Type=oneshot and ExecStart=\/my\/script. If so, just create a helper script that mails the output of journalctl -u &lt;unit&gt; &#8211;since today or something. Just don&#8217;t read the output of journalctl via a pipe!<\/p>\n<p>My solution is a little perl script:\u00a0<a href=\"https:\/\/tollana.d-tor.org\/notes-to-self\/wp-content\/uploads\/2016\/01\/mail-unit.pl_.txt\" rel=\"\">mail-unit.pl<\/a><\/p>\n<p>Just add StartExec=mail-unit.pl &lt;my unit name&gt; after your actual script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to mail the output of a systemd-timer unit by redirecting STDOUT to \/usr\/bin\/mail or something: forget it. For a long time SysAdmin used to good old crond it definitely doesn&#8217;t work as expected. As long as you redirect STDOUT in your script or program, you won&#8217;t get any output, because systemd redirects &hellip; <a href=\"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=157\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Mail from systemd-timers<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[51,86],"class_list":["post-157","post","type-post","status-publish","format-standard","hentry","category-linux","tag-systemd","tag-timers"],"_links":{"self":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=157"}],"version-history":[{"count":3,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/157\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}