Zip an excel file and email using script.

Hi All,

Currently i am using below script to attach excel and email from a Unix script.
uuencode ASC.xls|mailx -m -s "ABCD_subject`TZ=CST+24 date +%d-%b-%y`" email@email.com

Can anyone give me or help me in zipping excel and sending that email as the excel is very heavy.

Thanks,

gzip -c ASC.xls | uuencode ASC.xml.gz | mailx .....

Thanks Much!!!

Please suggest on how to write body for the email above.

I normally use something like:

cat << ! | mailx ......
Message body goes here
$(gzip -c ASC.xls | uuencode ASC.xls.gz)
!
echo "Hi All" >> cnt
echo "" >> cnt
echo "" >> cnt
cat cnt | gzip -c ASC.xls | uuencode .........

I am using the above format but i am getting attchment but not the body in the email"HI ALL".

All you've done here is compress your file cnt into a file called ASC.xls and sent that as an attachment. "HI ALL" is in the attachment!

That's not quite how I described it.

cat << ! | mailx ......
Message body goes here
$(gzip -c ASC.xls | uuencode ASC.xls.gz)
!

Hi could you please describe the above code whats the (!) in the code ?

It's just a "word" that marks the start, and end of a "here-document". It could be pretty much anything you like.

By convention, people often use either ! or EOF as "word"

cat << EOF | mailx ......
Message body goes here
$(gzip -c ASC.xls | uuencode ASC.xls.gz)
EOF

is the same thing.

The XLS file is encoded inside the here-document, and sent as an attachment in the mail.

can i keep the code given by you inside a shell script ???

because i am exporting the excel file using one more sql query...all these command are there in a shell script

Yes.


auto_repconnect  auto_sql auto_status 1>>auto_suc.xls 2>>auto_err
gzip -c auto_suc.xls | uuencode auto_suc.xml.gz |mailx -m -s "Subject" abc@xyz.com

this is inside a shell script(.sh) file
need to get msg body as well as attchment. tried several ways but failing. :frowning:

Look at mpack instead of uuencode & mailx.

It's very easy to use and you can send any attachments you want.

@Varu0612:

@Scottn:

Why are you using this code, instead of the code I showed you?

this is my original code.. which gives me excel attached zipped. i just want to add body to this code.