如何获取下面的 DISCUS 命令输出:
并将其转换为 HTML 电子邮件友好的内容?我已经编写了这样的 bash 脚本:
#!/bin/sh
discus > /tmp/discus.log
touch /tmp/diskchart.log
echo "To: [email protected]" > /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" [email protected] < /tmp/diskchart.log
#rm /tmp/discus.log /tmp/diskchart.log
但这会产生如下所示的输出:
有人知道如何处理实际邮件中出现的转义字符吗?我理想地希望看到如上所示的条形图。我正在运行 Ubuntu 12.04.1 LTS
答案1
你可以使用啊哈(也打包在一些 Linux 发行版中),将 ANSI 着色序列转换为 HTML:
#! /bin/sh -
sendmail -t -oi << EOF
To: [email protected]
Subject: Weekly Disk Report
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Disposition: inline
$(discus | aha)
EOF