Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

#!/bin/sh
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
1  
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
add comment

2 Answers

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)
EOF
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. –  Stephane 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
add comment

From the man page (man discus):

 -c     Disable color.

So to prevent those escape sequences...

discus -c > discus.out

Or, this might be done with ansifilter. Download, compile, and install. Then you can...

discus | ansifilter | mailx -s "Disk Report" me@mydomain.com

The mailx command would require heirloom-mailx.

sudo apt-get install heirloom-mailx
share|improve this answer
add comment

Your Answer

 
discard

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.