how to mail script output in table format

2019-02-21 06:39发布

I have the script output like below.

Current result:

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

Actual result to be like below (if possible with borders):

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

I need to mail above content in same format.

1条回答
老娘就宠你
2楼-- · 2019-02-21 07:13
#!/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"

Source: http://www.unix.com/302556864-post5.html

查看更多
登录 后发表回答