Hi, I have a shell script that send an excel file as an email attachment.
I would like to be able to send more than one excel attachment at any given time.
This is the script that currently send one attachment.
#!/bin/ksh
if test ! -z "${5}"
then
echo ""
echo "Error:"
echo " Too many arguments, try putting subject line in quotes."
echo ""
echo " Usage:"
echo " email-rep <filename> <recipient> <subject> <sender>"
echo ""
echo " Subject and Sender are not mandatory."
exit 1
else
filepath="${1}"
filename=`basename "${filepath}"`
filextn=${filename##*.}
recipient="${2}"
subject="${3}"
if [ "${4}" = "" ]
then
sender="ABC <abc@abc.com>"
else
sender="${4}"
fi
cat <<! | /usr/lib/sendmail -t -n
MIME-Version: 1.0
From:${sender}
To: ${recipient}
Subject: ${subject}
Content-Type: multipart/mixed; boundary="_boundarystring"
This is a multi-part message in MIME format.
--_boundarystring
Content-Transfer-Encoding:
Base64
Content-Type: application/vnd.ms-excel
Content-Disposition: attachment; filename="${filename}"
`java base64 "${filepath}"`
--_boundarystring--
!
fi
My idea was to ask for the recipients email address then the arguments after that would be the files to be sent. Then use a for loop on the bit right after the "This is a multi-part ....", as this is the bit that needs to be typed out again for multiple attachments.
when I put the do loop in the code, it looked like this:
This is a multi-part message in MIME format.
for i in $3 $4 $5
do
filepath="$i"
filename=`basename "${filepath}"`
--_boundarystring
Content-Transfer-Encoding:
Base64
Content-Type: application/vnd.ms-excel
Content-Disposition: attachment; filename="${filename}"
`java base64 "${filepath}"`
--_boundarystring
done
The program didn't seem to recognise the loop.
I am not very good at writing shell scripts and I literally just read up on loops today.
I would appreciate any suggestions or possible alternatives.
Thank you in advance.
Start Free Trial