Send attachment through sendmail

Hi,

I am trying to send log file of a job run in unix machince through sendmail.Though I am able to send the text but it is not sending as attachment.

Could you please look into the code and let me know where I have gone wrong

fdate=`date %Y%j`
file_wc="/global/spsnfs/home/oracle2/sps2arc/test/*_${fdate}.txt"
attachments=''
for f in `ls ${file_wc}`; do
attachments="$attachments
 
Content-Type: text/plain;
Content-Disposition: attachment; filename=`basename $f`

Your code is over-complex for a start. You don't need the `ls ${file_wc}` bit at all. Just use for f in ${file_wc}

You also have a missing " for the attachments= statement.

I don't see where you are trying to use sendmail either. The code sort of peters out and then gets lost after that.

Can you confirm that this is the correct code?

Robin

Hi,
Thanks for the reply.here is the complete code, i am tryng to get the attachment in the email which it is not sending

fdate=`date %Y%j`
file_wc="/global/test/*_${fdate}.txt"
boundary='=== MESSAGE ==='
attachments=''
for f in `ls ${file_wc}`; do
attachments="$attachments
--${boundary}
Content-Type: text/plain;
Content-Disposition: attachment; filename=`basename $f`

`cat $f`

"
done

message="<html>
<body>
<p> Attached are the
log files for the various types of data which was archived. Please review the
logs for any errors and take the appropriate action</p>
</body>
</html>"

cat <<EOM | /usr/lib/sendmail -t
To:  EMAIL IDS
Subject: Archival complete
MIME-Version: 1.0
Content-Type: MULTIPART/MIXED;
    BOUNDARY="${boundary}"

--${boundary}
Content-Type: text/html;

${message}

${attachments}

--${boundary}--
EOM

#TAR and compress logs
files=''
for f in `ls ${file_wc}`; do
  files="$files $f"
done
$v_tar -cPjf /global/archive_${date}.tbz ${files}
if [ "$?" -eq "0" ]; then
  rm -rf ${files}
fi
exit