Using mutt and cron to email w/attachment

Well…this was kind of a pain to get working, for an idiot like me. I wanted to get a tarred version of a particular log file via email – as an attachment – and I had no idea where to start. In other words, I wanted to have an email sent to me, with an attachment, using an automated (cron driven) script. The following little script, which uses mutt, did the trick. I found the info on the net, somewhere. The script, below, deletes an old .tar file and creates a new one, then performs the mail function (the important part). The “message.txt” file is the body of the email. A big thank you to someone, somewhere – I can’t recall where I finally dug this up.

#!/bin/sh
rm -rf logs.tar
cd /home/vpopmail/qtrap
tar -cvf logs.tar logs
cp ***tar /root
mutt -s “Qtrap Logs” -a logs.tar me@myemail.com,me_somwhere_else@aol.com \
< /root/message.txt

And my mail looks like this:

Leave a Reply