LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   sending attachments from sendmail in a script (https://www.linuxquestions.org/questions/linux-general-1/sending-attachments-from-sendmail-in-a-script-60772/)

pr0fess0r 05-20-2003 04:01 AM

sending attachments from sendmail in a script
 
Hi Guys

I have a shell script I am going to set up as a cron job. It dumps a MySQL database as a gzipped file. I want it to email that file to another address.

So far the script is:

#!/bin/sh
date=`date -I`
mysqldump --opt -Q -u root --password=***** contented | gzip > /home/username/.gnome-desktop/dbdump-$date.sql.gz

which works nicely

Now how do I send that file to user@domain.com using sendmail? I am on RH Linux 9, but this will eventually go to my ISP which may not be running RH so a generic answer would be great!

Many thanks!

unSpawn 05-20-2003 04:40 AM

What you want is a proper formatted MIME message: see mimencode or mpack.
// You could also do with some checks based on the error messages of the dump command, size of the message (use bzip2 vs gzip, or split if too large), use proper quoting (see date), make damn sure the file has the right permissions due to it having the passwd and not put the tmpfile in /home/username/.gnome-desktop, but in a proper temp directory...

pr0fess0r 05-20-2003 05:49 AM

Some hints?
 
Hi

Thanks for the tip. As I'm a newbie, could you give me a "best practise" example of how to fix the previous script (the .gnome-desktop path is just for testing, an ex-Windows user here:) and how to use mimeencode/sendmail?

cheers


All times are GMT -5. The time now is 03:00 PM.