Html output with awk/sendmail


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Html output with awk/sendmail
# 1  
Old 05-28-2019
Html output with awk/sendmail

Hello All,

I inherited maintenance of a script that uses awk on an input file (space delimited) and formats it into an html table and send out using sendmail. I know how to manipulate the print statements to add columns and rows, however that is the extent of my html knowlege. I've searched for potential solutions and haven't really found anything i could translate into applying to the logic in the script i have.


Here is the specific portion of the script that gener
Code:
ates the html table:


       awk ' BEGIN {
       print "From: <user@there.com> <Canary/Shorten Team: Morning Checkout>"
       print "To: <user@here.com>"
       print "MIME-Version: 1.0"
       print "Content-Type: text/html"
       print "Subject: ** Canary/Shorten TEST ENV Morning Checkout **"
       print "<html><body><table border=2 cellspacing=1 cellpadding=5 color=black>"
       print "<tr>"
       print "<font size="2" face="Calibri" color="blue">"
       print "<td> </td>";
       print "<td> </td>";
       print "<td> </td>";
       print "<td> </td>";
       print "</p>"
       print "</font>"
       print "</tr>"
       } {
          print "<tr>"
          print "<font size="2" face="Calibri" color="blue">"
          print "<td>"$1"</td>";
          print "<td>"$2"</td>";
          print "<td>"$3"</td>";
          print "<td>"$4"</td>";
          print "</tr>"
         } END {
                print "</table></body></html>"
               } ' ${mail_out} | /usr/sbin/sendmail -t


Example of input file.
Code:
ElasticSearch RED ACTIVE_SHARDS:174/174 ACTIVE_NODES:4/4
<url1> GREEN  

<url2> RED  


 Canary GREEN
<urlX> GREEN
<urlY> GREEN

What i'm trying to do is 3 fold.
  • 1. Change the subject so that if a variable in the code called OVERALL_STATUS is = RED, the subject would say:
    • ** Canary/Shorten TEST ENV Morning Checkout - RED **
    • If the variable OVERALL_STATUS is = GREEN then the subject would say:
    • ** Canary/Shorten TEST ENV Morning Checkout - GREEN **
  • 2. If the 2nd field in the file has the text "GREEN", then change the font color to green. If the 2nd field in the file has text "RED", then change the font color to red.

  • 3. Remove the column headers as we no longer use column headers for this script. I couldn't figure out how to remove them without breaking the logic. So it just prints 4 blank cells at top of table.


I have tried playing around with color just to see if i can change the background by using

Code:
   <td        bgcolor="#FF0000">$2</td>
and 

<td        bgcolor="green">$2</td>

And the color in the email received is not changed.


Any guidance would be greatly appreciated
# 2  
Old 05-28-2019
You should write the document in HTML and CSS first and get it working first.

Then after you get it working, then create a AWK script to create the document.

From your post, it seems the issue it not AWK, but CSS.
# 3  
Old 05-29-2019
While i appreciate the reply, as i eluded to in original post...i'm not that good with html and even less with CSS.
# 4  
Old 05-29-2019
Well, as I mentioned in my earlier post you should get an HTML page with proper CSS working before you try to compose that page with AWK.

Anyone can easily learn and should learn basic HTML and CSS.

Spend a day and learn the basics.
# 5  
Old 05-29-2019
You may want to see how far this gets you:
Code:
awk '
BEGIN   {#print "From: <user@there.com> <Canary/Shorten Team: Morning Checkout>"
         #print "To: <user@here.com>"
         #print "MIME-Version: 1.0"
         #print "Content-Type: text/html"
         #print "Subject: ** Canary/Shorten TEST ENV Morning Checkout **"
         print "<html><body><table border=2 cellspacing=1 cellpadding=5 color=black>"
         print "<tr>"
         print "<font size=\"2\" face=\"Calibri\" color=\"blue\">"
         print "</font>"
         print "</tr>"
        }
NF      {print "<tr>"
         print "<td><font color=\"" $2 "\">"$1"</font></td>";
         print "<td><font color=\"" $2 "\">"$2"</font></td>";
         print "<td><font color=\"" $2 "\">"$3"</font></td>";
         print "<td><font color=\"" $2 "\">"$4"</font></td>";
         print "</tr>"
        }
END     {print "</table></body></html>"
        } 
' file

But, be aware that (as has already been said) (quoted from font tag )
Quote:
The <font> tag is not supported in HTML5. Use CSS instead.
These 2 Users Gave Thanks to RudiC For This Post:
# 6  
Old 05-29-2019
Thank you RudiC! Got all 3 of my concerns fixed. Figured out the subject and header removal, rookie mistakes on my part. Your piece got the color changing i was looking for!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail cmd for html body and attachment not working

Hi, I am having trouble in sending a mail with html body and attachment (csv file). We don't have uuencode or mutt (not allowed to install as well) The below code is perfectly working for sending the html body alone: export MAILTO=abc@xyz.com export CONTENT="/home/abc/list.html"... (2 Replies)
Discussion started by: close2jay
2 Replies

2. UNIX for Dummies Questions & Answers

Sendmail with HTML body and attachment code issues

Hi, I was working on getting an HTML file in the mail body along with attaching a "csv" file to the mail. Below are the 2 parts of the code. I need help with the second part where I'm sending the mail. The HTML file as an attachment is perfect without any issues and with proper formatting.... (6 Replies)
Discussion started by: aster007
6 Replies

3. Shell Programming and Scripting

Email body not formatted with html and sendmail

Hi All, I am trying to send the contents of a file as email body. I am using html email and sendmail option of unix. I am using the below piece of code for the same : #!/usr/bin/ksh export MAILTO="email@domain.com" export SUBJECT="Report" export BODY="file_directory_path/test_file.txt"... (1 Reply)
Discussion started by: rockygsd
1 Replies

4. Shell Programming and Scripting

Sendmail with header and footer logo in HTML body

Hello, I need help with my script that will send email via sendmail command that will shows both the header and footer logo once the recepient receive the email (e.g. MS Outlook). When I tested to ran the script it will successfully send the email BUT UNFORTUNATELY it doesn't displayed the... (8 Replies)
Discussion started by: lawrence88
8 Replies

5. Shell Programming and Scripting

problem with sending mail from txt file having HTML code via sendmail -t

Hi, i have the following code in shell named as test3.sh.. #!/bin/sh . /home/<user>/.profile export dt=`date "+%d%b%y"` export tim=`date "+%d%b%y %HM:%MM"` cd export WD=`pwd` SID="<sid>" export SID export ORACLE_SID=$SID export ORACLE_HOME=/oracle/$SID/102_64 export... (4 Replies)
Discussion started by: jassi10781
4 Replies

6. UNIX for Dummies Questions & Answers

Send HTML graph using sendmail

Hi all. Urgent help required. I am trying to send and HTML/PNG fromat graph from UNIX using sendmail. The graph needs to be in the body of the HTML email and NOT an attachment.:wall: Any ideas and help will be really appreciated. Best regards, Willz (6 Replies)
Discussion started by: Willz
6 Replies

7. Shell Programming and Scripting

Sendmail with HTML body and attachment

I have an HTML file I am currently sending in the body of an email. I now have a need to send a csv attachment along with it. I can ONLY use sendmail as mutt and xmail etc are not on the server. Here is what I am currently using: It is possible to add code to add an attachment ??!? { ... (8 Replies)
Discussion started by: atelford
8 Replies

8. Shell Programming and Scripting

Problem in sending inline html with an attachment using sendmail

MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=border --border Content-Type: text/html Content-Disposition: inline <html><body><h2>This text should be displayed with html formatting</h2></body></html> --border Content-Type: text/plain Content-Disposition: attachment This text... (2 Replies)
Discussion started by: thulasidharan2k
2 Replies

9. Shell Programming and Scripting

Sendmail with html attachment and html body

Hi folks, I have a perl script which sends out email after successful completion of job as inline html, I want to send it out as two parts now as html inline and html attachment. see the attached script. Thanks in advance (1 Reply)
Discussion started by: sol_nov
1 Replies

10. Shell Programming and Scripting

awk script to search an html file and output links

hello. i want to make an awk script to search an html file and output all the links (e.g .html, .htm, .jpg, .doc, .pdf, etc..) inside it. also, i want the links that will be output to be split into 3 groups (separated by an empty line), the first group with links to other webpages (.html .htm etc),... (8 Replies)
Discussion started by: kyris
8 Replies
Login or Register to Ask a Question