0

I am sending an email by using below commands by combining all the output and sending in one email. It works fine for me.

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

Now I need to attach one file within the above email and that file is under temp folder with the name of chart. And while sending I need to send it as chart.html file.

So How can I modify my above command so that it can attach chart as chart.html file from temp folder in the email.

Hope I am clear to everyone. I am running SunOS.

Any suggestions will be appreciated.

Updates:-

If I need to add uuencode command in my shell script so it should be like below? or something else

mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com <<EOF
uuencode /tmp/chart chart.html
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
arsenal
  • 23,366
  • 85
  • 225
  • 331
  • possible duplicate of [How to send simple text file as attachment using HP-UX shell script?](http://stackoverflow.com/questions/6274325/how-to-send-simple-text-file-as-attachment-using-hp-ux-shell-script) – glenn jackman Aug 13 '12 at 05:50
  • Composing MIME messages with Python or Perl is way easier than doing it with shell scripts. – Paulo Scardine Aug 13 '12 at 09:12

3 Answers3

1
apt-get install sharutils

where run.sh is the attachment and hello is the message

(echo "hello"  ; uuencode run.sh run.sh ) | mailx -s "Testing 2" root@localhost



EMAILCONTENT="Data Successfully loaded into LIP_DATA_QUALITY table \n Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`\n Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`\n Error Percentage: $QUERY2 \n"
(echo $MAILCONTENT ; uuencode /tmp/chart chart.html ) | mailx -s "Testing 2" root@localhost


 ### OR
FILE="/tmp/email.content"
echo -e "Data Successfully loaded into LIP_DATA_QUALITY table \n Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`\n Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`\n Error Percentage: $QUERY2 \n" > $FILE 
(cat $FILE ; uuencode /tmp/chart chart.html ) | mailx -s "Testing 2" root@localhost
V H
  • 8,382
  • 2
  • 28
  • 48
  • I just upated my question with the way I am using `uuencode command` is right or not? Any thoughts will be appreciated. – arsenal Aug 13 '12 at 21:47
  • nope that is incorrect since you are carrying out the uuencode withing a string called EOF that you are passing to it the correct way would be : (as above new content added to this post) – V H Aug 16 '12 at 10:48
0

you can use a more versatile mail user agent like email from http://www.cleancode.org/projects/email which natively manages attachements

Stephane Rouberol
  • 4,286
  • 19
  • 18
0

The least necessary change to your shell script would be

`uuencode /tmp/chart chart.html`

(the backticks to have the command substitution of uuencode inserted in the here document).

Armali
  • 18,255
  • 14
  • 57
  • 171