Linux – Sending cron output as a text file attachment

attachmentcronemaillinux

I sysadmin a multiplayer game at CentOS 6.5 Linux server for a customer.

The customer has requested me to send the daily chat logs (to identify and ban agressive players) – as a text file attachement.

So I have come up with the following crontab command:

CONTENT_TYPE="text/plain; charset=utf-8"
MAILFROM=First.Last@gmail.com
LANG=en_US.UTF-8
#minute hour    mday    month   wday    command

55      23      *       *       *       
grep CHAT /var/log/game-`date +\%a`-*.txt | 
(echo 'The log is attached'; uuencode `date +\%A`.txt) | 
mail -s 'The daily chat log' First.Last@yandex.ru 

This works well for me with Gmail. But the customer is only using Mail.ru or Yandex.ru accounts and there it looks bad – no attachment is shown and he sees the uuencode output inline (aka begin 664 MT)Blah§$%&Blah):

Yandex mail screenshot

My question is if there is a safer way to send a cron job output by mail as a text file attachment. I know that a lot can be done with the help of perl (and I can program it), but I wonder if there is an easier way – with uuencode or mailx or some other utility?

Best Answer

mailx has the -a <filename> switch to add attachments. And on CentOS 6 by default /bin/mail is already mailx.