How to generate html reports through LINUX Scripting?

Hi All,

I am trying to generate a weekly HTML report using LINUX Scripting. This will have record counts of some files. (like below)

touch path/filename.html
echo  "Weekly Summary Report for Business Date : $P_BUS_DT">path/filename.html
export A1=`cat path/filename1.txt |wc -l`
echo  "A1 Groups : $A1">>path/filename.html
export A2=`cat path/filename2 |wc -l`
echo  "A2 Groups : $A2">>path/filename.html
etc...

But, this is generating a one line report like below
A1 : 100 A2:200

I want to generate it in 2 lines,
A1:100
A2:200

Is there a way I can generate html file in this way ?

Any help/thoughts will be helpful to resolve this issue.

Thanks much
Freddie

Can you:

od -bc filename.html

and post the result here?
(Remember to wrap the output with CodeTags)

Hi Joey,

Thanks a lot for your quick response. Here s what I could see when i did an od -bc filename.html .

I am sorry if pasting the output will cause any issues, I am not sure how I can add code tags to the output. :frowning:

0000000 103 120 115 107 040 127 145 145 153 154 171 040 123 165 155 155
          C   P   M   G       W   e   e   k   l   y       S   u   m   m
0000020 141 162 171 040 122 145 160 157 162 164 040 146 157 162 040 102
          a   r   y       R   e   p   o   r   t       f   o   r       B
0000040 165 163 151 156 145 163 163 040 104 141 164 145 040 072 040 015
          u   s   i   n   e   s   s       D   a   t   e       :      \r
0000060 012 124 157 164 141 154 040 111 156 151 164 151 141 154 040 123
         \n   T   o   t   a   l       I   n   i   t   i   a   l       S
0000100 165 163 160 145 143 164 163 040 072 040 063 061 071 061 060 064
          u   s   p   e   c   t   s       :       3   1   9   1   0   4
0000120 015 012 115 122 103 040 061 040 107 162 157 165 160 163 040 072
         \r  \n   M   R   C       1       G   r   o   u   p   s       :
0000140 040 063 060 015 012 115 122 103 040 110 040 107 162 157 165 160
              3   0  \r  \n   M   R   C       H       G   r   o   u   p
0000160 163 040 072 040 060 015 012 104 165 160 154 151 143 141 164 145
          s       :       0  \r  \n   D   u   p   l   i   c   a   t   e
0000200 040 122 145 143 157 162 144 163 040 072 040 060 015 012
              R   e   c   o   r   d   s       :       0  \r  \n
0000216

Thanks in advance,
Freddie

Hi Joey,

Can you lpls et me know your thoughts on this.

Thanks Much
Freddie

You need to generate a complete HTML document. Check out the tutorial here: HTML Tutorial

In short you need something along these lines:

(
  printf "<html>\n<head>\n<title>doument title</title>\n</head>\n<body>\n"
  echo  "Weekly Summary Report for Business Date : $P_BUS_DT"
  A1=`wc -l <path/filename1.txt `
  echo  "A1 Groups : $A1 <break>"
  A2=`wc -l <path/filename2 `
  echo  "A2 Groups : $A2"
  printf "</body>\n</html>\n"
) >path/filename.html

You'll also need to read up on how to properly format your output. For instance, if the output of any of your commands contains a greaterthan symbol (>) for instance, you'll need to convert it to a proper representation so that it is not interpreted by the browser as a part of HTML syntax.

If that's too much, then if you create a file with a .txt extention, most browsers render that as though it were contained in a complete HTML document with <pre> and </pre> tags around it.

IMO, before an inexperienced coder attempts to generate an HTML report from system commands, they should first create a script to generate a proper "Hello World" HTML page.

If you can create a "Hello World" HTML page, then it would be easy to then add more features, like output from a system command, etc.

Thanks Agama & Neo for your inputs.

I will try creating a simple HTML page.

In the meantime, currently I am creating this report as .rtf extension as all the lines in the output file was coming as one single line.(I have attached it for your reference). I can create this report as .txt & convert it to html through a simple (mv *.txt to *.html) command. But wondering whether there is a way to get the output in multiple lines through some simple workaround rather than going with the HTML tags etc.

Thanks much
Freddie