-1

Actually, i am making a self made tool "MOM" for my infrastructure team in my office. My tool has one text file "mom.txt" and a HTML file named as "mom.html" . I have a shell script that takes copy of "mom.html" and name it as momcpy.html I send this momcpy.html file in a mail as a report of meetings to my Team DL. I am attaching the image of my tool and different files here:

My Tool for sending "Minute of meetings" to Team mail:

enter image description here

enter image description here

Now here at the end, i have submit button , when i click on it , it sends the html report to the mail that is the file "momcpy.html"

My "mom.txt" file is given below :

    Saibal,Navnath,Taral,Sagar,Ankit,Prasham,Manika,Arvind,Gaurav,Abhijeet,Rohit,Madhu,Ganesh,Zahoor|
LSCRM:Abhijeet

MCRM:Arvind

TLGAPI:Bhargav

MOM:Manikaa|
Prod :
No major activity were scheduled and no issues were reported throughout the week.
Last weekend on Sunday, we performed Full bounce. We are doing so to allow any USDOTT transaction during this window while they do code-fix (they need CRM available at all times).
Coming weekend, we have ordering client Ef deployment and CK External BLM Phase 2 activity scheduled on both APH and STL.

Non-Prod:
Over the week, we released 1710 CT11 K2view to build: 220 and Env TRN3 to 1707 Build:300.
|
PROD:
We have 2Q OS Patching on DR and Production.
There was an issue of Sync reject long response time reported for NBI Market . It was run in debug mode to investigate further.
Coming weekend, the scheduled DR switchover activity got cancelled.
Coming weekend we have Weblogic phase 2 migration activity as well as weekly config build.

Non Prod:
We have 2Q OS Patching activity on QA and TRN envs.|
PROD:

WTC cleanup activity completed successfully.
No major issues reported.

NON PROD

Configuration changes on DB end for 1710 envs done.
There was an issue due to heap size on few jvms.Clients got impacted. We tried to do Rolling bounce but issue still persist. After half an hour issue got resolved itself.
|
No updates|
break|

So, on clicking the details that user input in Attendees, Agenda, LSCRMUpdates, MCRM Updates and Tlgapi Updates and Other Updates are saved in a text file "mom.txt" given above.

Now You can see that i have used pipe | as a delimiter to extract the different sections data that is given by user as an input.

Now my momcpy.html file that i send as a mail report its code:

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title>CRM Infra MOM Weekly Reports</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <link href='http://fonts.googleapis.com/css?family=Exo:700' rel='stylesheet' type='text/css'>
         <link rel="stylesheet" type="text/css" href="mom.css">
         <script src="mom.js"></script>
    </head>
    <body onLoad="xx()">
      <p class="exe1"><div id="content-wrap">
           <p class="exe1"><h1 valign="top">CRM Infra Weekly Report</h1></p>
            <br/>
          <p class="exe1"><table  align="center"  border="6" cellpadding="10" cellspacing="10">
                <tr>
                    <th height="15" style="font-size:20px;line-height:10px;" bgcolor="#808080"><label for="attendees">Attendees</label></th>
                </tr>
                <tr>
                    <td><textarea rows="10" cols="140">attendees</textarea></td>
                </tr>
                <tr>
                        <th height="12" bgcolor="#808080">Agenda:</th>
                </tr>
                <tr>
                    <td height="70" bgcolor="#FFFFFF">agenda.</td>
                </tr>
                 <tr>
                        <th height="12"  bgcolor="#808080"><label for="lscrm">LSCRM:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">lscrm</td>
                </tr>
                <tr>
                        <th height="12" bgcolor="#808080"><label for="mcrm">MCRM:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">mcrm</td>
                </tr>
                  <tr>
                        <th height="12" bgcolor="#808080"><label for="mcrm">TLGAPI:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">tlgapi</td>
                </tr>
                  <tr>
                        <th height="12" bgcolor="#808080"><label for="other">Other Updates:</label></th>
                </tr>
                <tr>
                    <td height="60" bgcolor="#FFFFFF">other</td>
                </tr>

            </table></p>
        </div></p>
    </body>
</html>

In this file i have a table with row and columns same like my Tool table structure. Here i have different variables in different rows like lscrm, mcrm, agenda, attendees, tlgapi and i replace those variables with the values present in mom.txt file (Value given as an input by user) using pipe as a delimiter.

I do this by using shell script:

#! /bin/bash -x
file='/home/websphe/tomcat/webapps/MOM/mom.txt'
file1='/home/websphe/tomcat/webapps/MOM/web/mom.html'
common_path='/home/websphe/tomcat/webapps/MOM/web/'
if test -s $file
   then
cp $file1 $common_path/momcpy.html
attendees=$( awk 'BEGIN { RS = "|" } NR == 1 { print }' $file )
echo "$attendees"
agenda=$( awk 'BEGIN { RS = "|" } NR == 2 { print }' $file )
echo "$agenda"
lscrm=$( awk 'BEGIN { RS = "|" } NR == 3 { print }' $file )
echo "$lscrm"
mcrm=$( awk 'BEGIN { RS = "|" } NR == 4 { print }' $file )
echo "$mcrm"
tlgapi=$( awk 'BEGIN { RS = "|" } NR == 5 { print }' $file )
echo  "$tlgapi"
other=$( awk 'BEGIN { RS = "|" } NR == 6 { print }' $file )
echo "$other"
trial=$( awk 'BEGIN { RS = "|" } NR == 7 { print }' $file )
perl -p -i -e "s#attendees#$attendees#g" $common_path/momcpy.html
perl -p -i -e "s#agenda#$agenda#g" $common_path/momcpy.html
perl -p -i -e "s#lscrm#$lscrm#g" $common_path/momcpy.html
perl -p -i -e "s#mcrm#$mcrm#g" $common_path/momcpy.html
perl -p -i -e "s#tlgapi#$tlgapi#g" $common_path/momcpy.html
perl -p -i -e "s#other#$other#g" $common_path/momcpy.html
perl -p -i -e "s#trial#$trial#g" $common_path/momcpy.html
     echo "`/bin/sh /home/websphe/tomcat/webapps/MOM/web/./mail.sh`"

             #rm $file
            # rm $common_path/momcpy.html
  else
    echo "Sorry no email sent :("
fi

~

MY PROBLEM STATEMENT NOW:

i Want to get the details in the same way as it is in "mom.txt" file for different sections say LSCRM Updates, MCRM Updates etc(or you can say input given by user). And since i am writing those input of text files into a HTML file, so i need to replace wherever the new line is coming with a
tag in HTML using above mentioned shell script NOTE: I only want to add <br> tag in the text input section not in each and every part of my html file. else it is getting aligned very down.

Currently i have used this in my script:

perl -p -i -e "s#attendees#$attendees#g" $common_path/momcpy.html
perl -p -i -e "s#agenda#$agenda#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#lscrm#$lscrm#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#mcrm#$mcrm#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#tlgapi#$tlgapi#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#other#$other#g" $common_path/momcpy.html | sed -i'' 's|\n|<br>|' $common_path/momcpy.html
perl -p -i -e "s#trial#$trial#g" $common_path/momcpy.html | sed -i'' 's|$|<br>|' $common_path/momcpy.html

But it is adding <br> tags everywhere in my HTML file and the table is getting alligned very down in browser Chrome or IE.

1

Easy, just remove the g flag in your commands as it causes to replace all occurences.

  • Thanks for quick reply , i have doubt as g flag is in perl statement and its output is an input to sed command where \n is replaced by <br> tag? – Abhijeet Anand Sep 8 '17 at 18:53
  • its not working getting same issue of <br> tag every where in html file. – Abhijeet Anand Sep 8 '17 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.