pages tagged sysadminBeuc's Bloghttps://blog.beuc.net/tags/sysadmin/Beuc's Blogikiwiki2020-01-04T23:50:31ZMini-sendmail... in bashhttps://blog.beuc.net/posts/Mini-sendmail..._in_bash/2020-01-04T23:50:31Z2012-02-13T22:18:46Z
<p>I recently faced an environment where there is no MTA.</p>
<p>WTF? The reason is that people who work there get security audits on a regular basis, and the security people are usually mo...deratly skilled guys who blindly run a set of scripts, e.g. by ordering to disable Apache modules that "where seen enabled in /etc/apache2/mods-available/"...</p>
<p>To avoid spending days arguing with them and nitpicking with non-technical managers, the system is trimmed to the minimum - and there is no MTA.
No MTA, so no cron output, so difficulty to understand why last night's cron job failed miserably.</p>
<p>Since it was not my role to reshape the whole business unit, I decided to hack a super-light, but functional way to get my cron output:</p>
<pre><code>cat <<'EOF' > /usr/sbin/sendmail
#!/bin/bash
(
echo "From me $(LANG=C date)"
cat
echo
) >> /var/mail/all
EOF
chmod 755 /usr/sbin/sendmail
</code></pre>
<p>It works! <img src="https://blog.beuc.net/smileys/smile.png" alt=":)" /></p>
<p>There is a companion logrotate script, to avoid filling the file system:</p>
<pre><code>cat <<'EOF' > /etc/logrotate.d/mail-all
/var/mail/all {
daily
rotate 10
compress
delaycompress
notifempty
create 622 root mail
}
EOF
</code></pre>
<p>Bootstrap with:</p>
<pre><code>touch /var/mail/all
logrotate -f /var/mail/all
</code></pre>
<p>You now can check your sys-mails with:</p>
<pre><code>mutt -f /var/mail/all
</code></pre>
<p><img src="https://blog.beuc.net/smileys/smile4.png" alt=";)" /></p>