Wednesday, October 16, 2013

Error Sending Multiple Attachments in UNIX Mail

www.unixbabuforum.inI'm trying to send email with multiple attachments. My script works fine if i use below line to send mail: 

(cat $GENESIS_HOME/B2B/SGTL/test_msg1; uuencode TEST_20080516121212_output.csv TEST_20080516121212_output.csv; uuencode TEST_20080520121212_output.csv TEST_20080520121212_output.csv) | mail -s "TEST REPORT " $MAIL_LIST 

However,the files that i need to attach are not fixed. It will be based on the input file name and will have more than 2 input files. So i used the script as below: 

(cat $GENESIS_HOME/B2B/SGTL/test_msg1; ${attachList}) | mail -s "TEST REPORT " $MAIL_LIST 

attachList is getting from script as below: 

for infile in $files 
do 
TEMP1=`echo $infile | cut -d'.' -f 1` 
print "\tTEMP1 = ${TEMP1} " >> ${LOG} 
TEMP="$TEMP1"_output.csv 
cd $FILE_PATH 
print "\tTEMP ${TEMP} \n" >> ${LOG} 

if [ -f $TEMP ]; then 
attachList="${attachList}; uuencode $TEMP $TEMP" 
print "\tattachList $attachList \n" >> ${LOG} 
fi 
done 

count=${#attachList} 
print "\tcount = $count \n" >> ${LOG} 
attachList=`echo $attachList | cut -c 3-$count` 
print "\tattachList -$attachList- \n" >> ${LOG} 

it works fine if i have only 1 input file. But if i have 2 input files, i got error: 
Usage: uuencode [-m] [infile] remotefile 


www.unixbabuforum.inTry: 
(cat $GENESIS_HOME/B2B/SGTL/test_msg1; eval ${attachList}) | mail -s "TEST 
REPORT " $MAIL_LIST 
Or, instead of calculating $attachList at all: 
(cat $GENESIS_HOME/B2B/SGTL/test_msg1; for f in $files ; do uuencode $file 
$file ; done | mail -s "TEST REPORT " $MAIL_LIST 

0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM