Thej Thej -4 years ago 203
Linux Question

how to mail script output in table format

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.

Answer Source
#!/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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download