uuencode doesn't work properly for attaching files with my below command
Question
I am trying to attach one file
and send few echo messages
in the Body of an email using mailx and uuencode
. I have below command which I have added them together, and uuencode doesn't work properly but I get echo message properly in my email.
How can I make uuencode works here? Something wrong I am doing here I guess while combing uuencode with mailx?
(uuencode /tmp/chart.html percentage_graph.html) | mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table
Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`
Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`
Error Percentage: $QUERY2
EOF
But for testing purpose if I issue below command to see whether I am getting any html file or not in an attachment, then I get an email with the attachment properly.
(uuencode /tmp/chart.html percentage_graph.html) | mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com
Then what's wrong in my first command when I combine them together?
Solution
The mailx
command can get its input from the pipe (uuencode) or the heredoc (<< EOF). But not both.
This may work for you:
$ mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@example.com rj@example.com <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table
Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`
Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`
Error Percentage: $QUERY2
$(uuencode /tmp/chart.html percentage_graph.html)
EOF
Alternately, consider using something like mutt which will let you attach files separately from the body of the message.
OTHER TIPS
uuencode doesn't read stdin if you give it an input filename as you have done here. That's because it encodes a single file. if you want to encode two files, you need to combine them together somehow first. You could just use cat
if concantenating them is ok:
cat /tmp/chart.html - | uuencode percentage_graph.html | mailx .... << EOF
..stuff to append to chart.html
EOF