[Solved] Shell script output in HTML or with table like results and mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Shell script output in HTML or with table like results and mail
# 1  
Old 01-09-2014
[Solved] Shell script output in HTML or with table like results and mail

Hello,
Currently i have a script which will disply the results in plain text format.
I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email.
Please help me how i can do that.


I am using below script for sending the content:
Code:
filesend=filename
cat mail_ids.txt |while read line
do
  elm -s "TEST" $line < $filesend
done


Last edited by joy lobo; 01-20-2014 at 08:53 AM.. Reason: code tags...
# 2  
Old 01-09-2014
you can try some thing like this
Code:
cat new
SERVER DB TABLE FREE SPACE
111.11.11.11 xyz ABCD 1000 YES
111.11.11.11 xyz ABCD 1000 YES
111.11.11.11 xyz ABCD 1000 YES
111.11.11.11 xyz ABCD 1000 YES

Code:
awk 'BEGIN { print "<table borader=1>"} {print "<tr>"; for(i=1;i<=NF;i++)print "<td><FONT COLOR=BLUE FACE="Geneva, Arial" SIZE=6>" $i"</FONT></td>";\
> print "</tr>"} END{print "</table>" }' new > temp.html

to email temp.html
Code:
(
echo "From: abcd@abcd.com "
echo "To: xyz@xyz.com"
echo "MIME-Version: 1.0"
echo "Subject: Test HTML e-mail."
echo "Content-Type: text/html"
cat $1
)|sendmail -t

# 3  
Old 01-09-2014
Thanx for your reply.......but can you pls give me the both on into one script.
# 4  
Old 01-09-2014
Code:
awk '
        BEGIN {
                print "From: from@domain.com"
                print "To: to@domain.com"
                print "MIME-Version: 1.0"
                print "Content-Type: text/html"
                print "Subject: Email Subject"
                print "<html><body>"
                print "<table border=1 cellspacing=2 cellpadding=2>"
        }
        !/^#/ && /^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td><b>" $i "<b></td>"
                print "</tr>"
        }
        !/^#/ && !/^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td>" $i "</td>"
                print "</tr>"
        }
        END {
                print "</table></body></html>"
        }
' inputfile | /usr/sbin/sendmail -t

Change the formatting as per your needs.
This User Gave Thanks to Yoda For This Post:
# 5  
Old 01-16-2014
Thnax yoda,

i hv used this code and its working fine.

but i am facing lil issue with merging the cells with same string.
means name "111.11.11.11" should be only once in mail with merged cell.

looking forward for your support.

---------- Post updated at 05:13 AM ---------- Previous update was at 02:10 AM ----------

can anyone help me out.........
# 6  
Old 01-16-2014
Do not bump up questions if they are not answered promptly.

Assuming first field is sorted, you could read the input file twice and use rowspan attribute to merge cells:
Code:
awk '
        BEGIN {
                print "From: from@domain.com"
                print "To: to@domain.com"
                print "MIME-Version: 1.0"
                print "Content-Type: text/html"
                print "Subject: Email Subject"
                print "<html><body>"
                print "<table border=1 cellspacing=2 cellpadding=2>"
        }
        NR == FNR {
                if ( $0 !~ /^#/ && $0 !~ /^S/ )
                        C[$1]++
                next
        }
        !/^#/ && /^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td><b>" $i "</b></td>"
                print "</tr>"
        }
        !/^#/ && !/^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                {
                        if ( i == 1 && !( $i in R ) )
                        {
                                print "<td rowspan=" C[$i] ">" $i "</td>"
                                R[$i]
                        }
                        if ( i > 1 )
                                 print "<td>" $i "</td>"
                }
                print "</tr>"
        }
        END {
                print "</table></body></html>"
        }
' inputfile inputfile | /usr/sbin/sendmail -t

This User Gave Thanks to Yoda For This Post:
# 7  
Old 01-17-2014
thanx for reply.....

i made script as per above:
value which is more than 80 will come in RED color.

##################################
Code:
        NR == FNR {
                if ( $0 !~ /^#/ && $0 !~ /^S/ )
                        C[$1]++
                next
        }
        !/^#/ && /^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td><b>" $i "</b></td>"
                print "</tr>"
        }
        !/^#/ && !/^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                {
                        if ( i == 1 && !( $i in R ) )
                        {
                                print "<td rowspan=" C[$i] ">" $i "</td>"
                                R[$i]
                        }
                        if ( i > 1 )
                        if ($3 >=80 )
                                   print "<td> <FONT COLOR=RED FACE="Geneva,Arial"SIZE=9 >"  $i  "</td>"
                        else
                                   print "<td> <FONT COLOR=BLACK FACE="Geneva,Arial"SIZE=9 >"  $i  "</td>"

                }
                print "</tr>"
        }
        END {
                print "</table></body></html>"
        }

' file file

######################################

but for every line which contains numeric value "9" in third field is coming in red colour.

THANX.

Last edited by Franklin52; 01-17-2014 at 03:18 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Postgre Query results as Email HTML table

Hello, I'm trying to send email from Greenplum query results as HTML table with status Red/Green Select Server, Last_Date from Table; Results Server, Last_Date Prod, 2018-04-09 Final email Output in HTML format Server Status LastDate Prod GREEN(BOX) 2018-04-09 (if... (2 Replies)
Discussion started by: krux_rap
2 Replies

2. Shell Programming and Scripting

Convert shell script output txt file to html table

My concnern related to the post -Convert shell script output txt file to html table, in this how to print the heading as color. awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename> (8 Replies)
Discussion started by: sarajobmai
8 Replies

3. Shell Programming and Scripting

I want query output to send on mail using table tag and output should be in table

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (21 Replies)
Discussion started by: ankit.mca.aaidu
21 Replies

4. Shell Programming and Scripting

Insert an image in HTML mail sent from Shell script

Hi Shell Experts I am trying to insert an image into HTML email through shell script send mail, I have the email text file which included body and the images included in it in html format. Through my Shell script, I am calling the text file and send it through email so it it sends the email with... (21 Replies)
Discussion started by: anji009
21 Replies

5. Shell Programming and Scripting

[SOLVED] Read html attachment from /var/mail

Hi, I am receiving an email to the server with a html attachment. When I check the /var/mail the attachment is showing as junk characters. I want to move that html file to a particular location in that server. Please help me. Regards Neethu (4 Replies)
Discussion started by: Neethu
4 Replies

6. Shell Programming and Scripting

Convert shell script output txt file to html table

Hi, I have script which generates the output as below: Jobname Date Time Status abc 12/9/11 17:00 Completed xyz 13/9/11 21:00 Running I have the output as a text file. I need to convert it into a HTML Table and sent it thru email ... (6 Replies)
Discussion started by: a12ka4
6 Replies

7. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

8. Shell Programming and Scripting

shell script output in HTML or with table like results

Hello, Currently i have a ksh script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html or excel format and send that content as email. Please help me how i can do... (2 Replies)
Discussion started by: kotasateesh
2 Replies

9. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

10. Shell Programming and Scripting

have a shell script done in pl/sql and want output in html

I have this shell script where I have both pl/sql and sql. But want to have a snigle output file where the result of each cursors are in HTML tables. I was able to do that on my old script but it was only sql scripts (no pl/sql). Can I do have such outputs now with my new script where I... (2 Replies)
Discussion started by: arobert
2 Replies
Login or Register to Ask a Question