On Tue, Dec 09, 2003 at 05:08:34PM -0300, Ismael M. Arias wrote: >El planteo es por que tengo un programa en C que envia mails texto plano >con sockets y me surge la necesidad de agregarle un archivo adjunto. El ejemplo adjunto es en bash (no en C) pero podría ayudar algo. Este script encripta 4 reportes por cada host que aparezca como parametro y los envia como adjuntos en un mensaje de correo. Aníbal Monsalve Salazar -- .''`. Debian GNU/Linux | Building 28C : :' : Free Operating System | Monash University VIC 3800 `. `' http://debian.org/ | Australia `- |
#!/bin/bash # First param is the messageid messageid=$1 shift # Subsequent parameters are hostnames for host in $*; do rm -f tmp/$host-{cis,patchk,pkginfo,secinfo}* tmp/$host-bl.mail email=`grep ^$host rpt/hosts|sed "s/^$host://"` for report in cis patchk pkginfo secinfo; do if [ -e $host/$report-bl.gz ]; then cp -p $host/$report-bl.gz tmp/$host-$report-bl.gz gunzip tmp/$host-$report-bl.gz /usr/local/bin/gpg --armor --recipient $email --quiet --batch --yes --encrypt tmp/$host-$report-bl fi done if [ -e tmp/$host-cis-bl.asc -a -e tmp/$host-patchk-bl.asc -a -e tmp/$host-pkginfo-bl.asc -a -e tmp/$host-secinfo-bl.asc ]; then boundary=`date +%Y%m%d%H%M%S`@slcm1.its.monash.edu.au date=`date -u +"%a, %e %b %Y %T +0000" | sed 's/, /, 0/'` cat > tmp/$host-bl.mail << FIN Subject: baseline reports for $host To: $email Date: $date Message-id: <$boundary> References: $messageid In-reply-to: $messageid MIME-version: 1.0 Content-type: MULTIPART/MIXED; BOUNDARY="$boundary" This is a multi-part message in MIME format. --$boundary Content-type: text/plain; format=flowed; charset=us-ascii Content-transfer-encoding: 7BIT Please find attached the baseline reports for $host. FIN for report in cis patchk pkginfo secinfo; do cat >> tmp/$host-bl.mail << FIN --$boundary Content-type: application/pgp; x-action=encrypt; format=text; name=$host-$report-bl.asc Content-disposition: inline; filename=$host-$report-bl.asc Content-transfer-encoding: 7BIT FIN cat tmp/$host-$report-bl.asc >> tmp/$host-bl.mail done echo >> tmp/$host-bl.mail echo --$boundary-- >> tmp/$host-bl.mail /usr/lib/sendmail -t < tmp/$host-bl.mail rm -f tmp/$host-{cis,patchk,pkginfo,secinfo}* fi done
Attachment:
pgp9gRL954RMt.pgp
Description: PGP signature