Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I take the DISCUS command output below:

Screenshot of colored discus output

and convert it into something HTML email friendly? I've bash scripted something like this:

discus > /tmp/discus.log
touch /tmp/diskchart.log
    echo "To: myaddy@domain.com" > /tmp/diskchart.log
    echo "Subject: Weekly Disk Report" >> /tmp/diskchart.log
    echo "MIME-Version: 1.0" >> /tmp/diskchart.log
    echo "Content-Type: text/html; charset=\"us-ascii\"" >> /tmp/diskchart.log
    echo "Content-Disposition: inline" >> /tmp/diskchart.log
    echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">" >> /tmp/diskchart.log
    echo "<html>" >> /tmp/diskchart.log
    echo "<div>" >> /tmp/diskchart.log
    cat /tmp/discus.log | grep / | grep -v run | /usr/bin/awk '{print $1}{print $9}' >> /tmp/diskchart.log
    echo "</div>" >> /tmp/diskchart.log
    echo "</html>" >> /tmp/diskchart.log
    mail -s "SAT Weekly Disk Report" myaddy@domain.com < /tmp/diskchart.log
#rm  /tmp/discus.log /tmp/diskchart.log

but that produces an output which looks like this:

Screenshot of output with escape characters

Anyone know how to deal with the escape characters showing up in the actual mail? I'd ideally like to see the bar graph as shown above. I'm running Ubuntu 12.04.1 LTS

share|improve this question
are you sure you want text/html? text/plain would be adequate (and better) for a simple email like this. also, you don't need the two grep statements, awk can do regexp matching. try discus -c | awk '/\// && !/\/run/ {print $1,$9}' – cas Jan 5 '13 at 0:03
Thanks for that pointer Craig. Very much appreciated :) – Faisal Humayun Jan 6 '13 at 5:16
Combined with Stephane's reply, I actually ended up using "pydf" instead of "Discus" for the relevant mounts. Worked out brilliantly ! – Faisal Humayun Jan 6 '13 at 5:30

You could use aha (also packaged in some Linux distributions), to convert the ANSI colouring sequences to HTML:

#! /bin/sh -
sendmail -t -oi << EOF
To: myaddy@domain.com
Subject: Weekly Disk Report
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Disposition: inline

$(discus | aha)
share|improve this answer
good answer, a herenow document is a much better (certainly more readable) way than lots of echo statements. The discus output needs to be surrounded by <pre> and </pre> tags, otherwise the columns wont line up properly when displayed...or send the mail as text/plain. or, as Faisal wanted only fields 1 and 9, use discus -c | awk '/\// && !/\/run/ {print $1,$9}' – cas Jan 5 '13 at 0:00
@CraigSanders, my version of aha at least does include the <pre>, </pre> tags. – Stéphane Chazelas Jan 5 '13 at 9:08
Thank you @ Stephane Chazelas & Craig Sanders. This really gets me headed in the right direction. Much obliged! PS - Thanks to moderator for adding images inline :) – Faisal Humayun Jan 6 '13 at 5:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.