linux - 如何以表格格式邮寄脚本输出

标签 linux bash shell email

我的脚本输出如下。

当前结果:

Filename Destname rowcount bytesize
file1 default 1488 2248
file2 default 123 657
file3 default 123 456
file4 default 567 124

实际结果如下(如果可能有边框):

Filename  Destname  rowcount  bytesize
file1     default   1488      2248
file2     default   123       657
file3     default   123       456
file4     default   567       124

我需要以相同的格式邮寄以上内容。

最佳答案

#!/bin/bash

input="/path/to/your/file.txt"
tmpfile="/path/to/tmpfile.html"

echo 'Content-Type: text/html; charset="us-ascii" ' > "$tmpfile"
awk 'BEGIN{print "<html><body><table border=1>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table></body></html>"}' "$input" >> "$tmpfile"
mail -s "test" abc@xyz.com < "$tmpfile"

来源:http://www.unix.com/302556864-post5.html

关于linux - 如何以表格格式邮寄脚本输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34573527/

相关文章:

c - 添加转换后对象呈现奇怪

python - 尝试从华为调制解调器读取消息时出现错误 125002

regex - 在 Linux shell 中,如何使用正则表达式来过滤其他命令的输出。

linux - 如果其中一个文件存在,则在 bash shell 脚本中发送电子邮件警报

mysql - 需要从shell脚本连接数据库mysql(linux centos7)

linux - 缺少库 symLite Ubuntu 14.10 x64

linux - 未定义的图书馆引用,所以我怎么能找到正确的路径?

Linux如何等待远程pid(telnet)

linux - 验证 bash 中的一些参数

linux - 参数未传递给 shell 脚本 copyfile.sh : 1: copyfile. sh: [d: 未找到