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.
1 2 3 4 5 6 7 |
#!/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 |
UPDATE
Okay – so on Ubuntu 10 (the above was on Centos 5.5, as I recall) there are some significant differences. For one thing, with newer versions of this thing the attachment info must come after the email address. Also, when I downloaded mutt via apt it also installed postfix. Apparently, mutt wants to use Postfix, although postfix does not start at boot time – so there’s no conflict with my Qmail setup. However, my new script has to shutdown Qmail, for an instant, and start and stop Postfix to make all of this work. Here’s an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/bin/sh cd / tar -cvf directory.tar directory cp *tar /root cd /root chmod 777 *tar qmailctl stop sleep 2 /etc/init.d/postfix start sleep 2 mutt -s "My Mutt Email" guysterdoo@gmail.com -a directory.tar < Hello sleep 2 /etc/init.d/postfix stop sleep 2 qmailctl start |
UPDATE 2
Okay…….ack! I have no idea what’s going on, but, the above worked off and on…… The following seems to be a far more reliable method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/bin/sh qmailctl stop sleep 4 /etc/init.d/postfix start cd /root rm -rf **qmail-send*tar cd /var/log/qmail rm -rf *tar tar -cvf $(date +%m_%d_%Y_TIME=%H%M)_qmail-send.tar qmail-send cp *tar /root rm -rf *tar cd /root cat Message.txt | mutt -s Your_Send_Logs guy_merH77@gmail.com -a *qmail-send.tar sleep 12 /etc/init.d/postfix stop sleep 3 qmailctl start |