Html output in correct format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Html output in correct format
# 1  
Old 01-31-2014
Html output in correct format

Hi,

I am running two scripts as below.
In Script 1 i am getting correct output in proper HTML format while in script 2 i am not getting output in mail and only html code is getting printed.I want to get the output of script 2.
Please guide.

Code:
 
1.IFILE=/home/home01/Report.csv
if [ -r $IFILE ]  #Checks if file exists and readable
then
if awk -F, '{ T += $13 } END { exit(!T) }' ${IFILE}
then
awk -F, 'BEGIN{
 c=split("3,4,8,9,13", col)
 print "To: abc@gmail.com"
 print "Subject:REPORT"
 print "MIME-Version: 1.0"
 print "Content-Type: text/html"
 print "Content-Disposition: inline\n"
 print "<HTML><TABLE border=1>"
 print "<TH>Code1</TH><TH>Bus</TH><TH>File1</TH>"
 print "<TH>Code2</TH><TH>#tra</TH><TH>"
}
NR>4 {
 printf "<TR>"
 for(i=1;i<=c;i++) printf "<TD>%s</TD>", $col[i]
 print "</TR>"
}
END{
  print "</TABLE></BODY></HTML>"
} ' ${IFILE} | sendmail -t
 
 
2.
log=/home/home01
rndt=`date +"%m%d%y%H%M%S"`
OFILE1="${log}/${rndt}.log"
echo "                                                                REPORT                                                  " >> $OFILE1
echo "                                                                                                                                        " >> ${OFILE1}
echo "                                                                                                                                        " >> ${OFILE1}
echo "###################################################################################################################################" >> $OFILE1
echo "Report Verification" >> $OFILE1
echo "#####################################################################################" >> $OFILE1
echo "1. Error details:" >> $OFILE1
echo "   
IFILE=/home/home01/Report.csv
if [ -r $IFILE ]  #Checks if file exists and readable
then
if awk -F, '{ T += $13 } END { exit(!T) }' ${IFILE}
then
result=$(awk -F, '
BEGIN{
 c=split("3,4,8,9,13", col)
 print "To: abc@gmail.com"
 print "Subject: REPORT"
 print "MIME-Version: 1.0"
 print "Content-Type: text/html"
 print "Content-Disposition: inline\n"
 print "<HTML><TABLE border=1>"
 print "<TH>Code1</TH><TH>Bus</TH><TH>File1</TH>"
 print "<TH>Code2</TH><TH>#tra</TH><TH>"
}
NR>4 {
 printf "<TR>"
 for(i=1;i<=c;i++) printf "<TD>%s</TD>", $col[i]
 print "</TR>"
}
END{
  print "</TABLE></BODY></HTML>"
} ' ${IFILE})
echo $result >>$OFILE1
fi
fi
echo "This is an automatically generated message from Source Feed Reconciliation Job. Please do not reply." >> $OFILE1
 
cat $OFILE1 | mail -s "Report" abc@gmail.com

# 2  
Old 01-31-2014
Why are you writing MIME headers into your output file and using mail with options?

Also you should not write lines before your MIME headers in your output file.
# 3  
Old 01-31-2014
Can you pls guide what excactly should be written and how?
Also how come script 1 is working perfectly fine and output not coming in Script 2.
# 4  
Old 01-31-2014
Remove all echo statements prior to writing MIME headers and use sendmail instead.
# 5  
Old 01-31-2014
all the echo statements are getting printed correctly.
I triied sendmail -t option in script 2 but still the output is same.
below code is not getting executed corrcetly in 2nd script:
Not sure if i am assgning the output of awk variable correctly and then mailing it in correct way..


Code:
 
IFILE=/home/home01/Report.csv
if [ -r $IFILE ]  #Checks if file exists and readable
then
if awk -F, '{ T += $13 } END { exit(!T) }' ${IFILE}
then
result=$(awk -F, '
BEGIN{
c=split("3,4,8,9,13", col)
print "To: abc@gmail.com"
print "Subject: REPORT"
print "MIME-Version: 1.0"
print "Content-Type: text/html"
print "Content-Disposition: inline\n"
print "<HTML><TABLE border=1>"
print "<TH>Code1</TH><TH>Bus</TH><TH>File1</TH>"
print "<TH>Code2</TH><TH>#tra</TH><TH>"
}
NR>4 {
printf "<TR>"
for(i=1;i<=c;i++) printf "<TD>%s</TD>", $col[i]
print "</TR>"
}
END{
  print "</TABLE></BODY></HTML>"
} ' ${IFILE})
echo $result >>$OFILE1
fi
fi

# 6  
Old 01-31-2014
Instead of assigning awk output to variable you can simply redirect it to file:
Code:
END{
  print "</TABLE></BODY></HTML>"
} ' ${IFILE} >> "$OFILE1"

Finally check the content of $OFILE1 and verify if it has data as expected.
# 7  
Old 01-31-2014
I tried below but not working:

Code:
 
} ' ${IFILE} >> $OFILE1

But still output not coming and something loke below is getting printed:

Code:
 
<TR><TD>* * * * * End Of Report * * * * *</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR>
</TABLE></BODY></HTML>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arranging the command output into an html table format

Hi, I need to format a command output for the beolow command: runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | grep -v "Certificates in database" The output will be: "ABC - cert name" From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT ... (3 Replies)
Discussion started by: bdpl
3 Replies

2. Shell Programming and Scripting

Script to generate HTML output format listing like orasnap

Hi, Is there any UNIX scripts out there that generates a listing output of some sort similar to OraSnap At the moment, I have a script that I run on multiple servers that has multiple databases and just querying the database sizes of those databases. It generates a text files that contains... (0 Replies)
Discussion started by: newbie_01
0 Replies

3. Shell Programming and Scripting

Loop to convert text output in the HTML format

Hello Everyone, I have a sample file raw.txt as shown below : Drive Bays Bay Name : SD-2C Number of Standby Power Supplies : 4 Number of Drive Enclosures : 12 Summary Status of Contained Modules All... (6 Replies)
Discussion started by: rahul2662
6 Replies

4. Shell Programming and Scripting

Output not in correct format - cd script

I have a script that looks like this: dirname2=/usr/tmp/filelist/*/* for dirname2 in /tmp/filelist/*/*; do (cd $dirname2/catalog ||echo "file does not exist" && echo "$dirname2" |cut -d '/' -f 7,8 && echo $i && ls -la |awk 'NR>3 {SUM += $5} END { print "Total number of kb " SUM }');done... (2 Replies)
Discussion started by: newbie2010
2 Replies

5. Shell Programming and Scripting

How to check if date format is correct?

Hi! how do i know if the input is the same as the required date format? the date should be dd/mm/YYYY ex. 2/3/2012 or 15/11/2012 all the following conditions must return an error: *input of string *day is > 31 or < 1 *month is > 12 or < 1 *year is < 2013 suppose the date format is stored... (1 Reply)
Discussion started by: angilulu
1 Replies

6. Shell Programming and Scripting

Dates not comparing correct even the same format

I have the date of the file passed into a variable also current date formatted same passed into a separate variable and compare the two with an if statement and statement always comes up false. Even though I verified the dates. Any help would be awesome. Filecrtdate=`ls -l $i | awk '{print... (19 Replies)
Discussion started by: coderanger
19 Replies

7. Shell Programming and Scripting

Correct a pattern format using sed

hi all I have a file with many lines like aa;bb;cc;dd;ee bb;aa;dd;ee;bb cc;ee;bb;dd;aa ee;cc;bb;aa;dd . . . etc The first line is in right format,Please help me how to use "SED" to change the rest of the lines to the format like line 1 thank all! (1 Reply)
Discussion started by: yuesko
1 Replies

8. Shell Programming and Scripting

Exit if date not in correct format

Can somone take a look at this script for me - I'm trying to get it to exit if the format of dateToLookFor is not in the format YYYYMMDD: function search { cd $logsloc echo "Enter date in format YYYYMMDD (enter to exit):" read dateToLookFor echo $dateToLookFor | grep -q ... (2 Replies)
Discussion started by: rich@ardz
2 Replies

9. Shell Programming and Scripting

how to display the output file in an html format using perl

Hi, I have written a perl script to dispaly some statements from a file but i want the output statements to be dispalyed in an HTML format.Is it possible for me to do in perl scripting? Please help me with ur thoughts. Thanks In Advance Meva. (1 Reply)
Discussion started by: meva
1 Replies

10. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question