0

I want to convert .csv file to HTML format below code .The while loop is not getting executed in the script.The while is being ignored and the control directly goes to the last line.The newfile contains the data generated from a SQL query. .csv file has been re-directed to newfile . Please find below code.

    Log_Path="/home/ggowner/ODI_MONITORING"
    cd $Log_Path

    logFile="model-A_snpsession_`date +%d%m%y`.csv"


    sqlplus -s  MODA_WORK_REPO/*****#@wcdsa<< EOSQL

    SET COLSEP ,
    SET PAGESIZE 700
    SET LINESIZE 700

    spool ${logFile}

     select to_char(sess_beg,'dd/mm/yyyy') "DATE",sess_name scenario,min(nb_ins),max(nb_ins), avg(nb_ins), min(sess_dur), max(sess_dur),avg(sess_dur),count(1),sum(NB_INS)
        from snp_session where to_date(sess_beg,'dd/mm/yyyy') >= to_date(sysdate,'dd/mm/yyyy')
        group by to_char(sess_beg,'dd/mm/yyyy'),sess_name order by sess_name;

    spool off
    quit
    EOSQL

    prepare_HTML()
    {
    cat $logFile >newfile
    echo "<HTML>" > outfile1.html
    echo "<head><b><u><FONT SIZE="3" COLOR="Green" >REF ODI MONITORING</b></u> 
    <br><br><br></head>" >>outfile1.html
    echo "<table style=" double black"  border="1" cellspacing="0" 
    cellpadding="0" bordercolor="maroon" bgcolor="silver"  >" >>outfile1.html
    echo "<basefont face="Calibri" size="2" >" >>outfile1.html
    echo "<tr><td>DATE</td><td>SCENARIO</td><td>MIN(NB_INS)</td><td>MAX(NB_INS) 
   </td><td>AVG(NB_INS)</td><td>MIN(SESS_DUR)</td><td>MAX(SESS_DUR)</td> 
       <td>AVG(SESS_DUR)</td><td>count(1)</td><td>sum(nb_ins)</td></tr>" 
       >>outfile1.html
       sed -i 's/ //g' newfile
       while read line
        do
echo ""
echo "<tr ALIGN="Left"><td>" >>outfile1.html
echo "start"
var=`echo $line|cut -d '=' -f1`
var1=`echo $var|cut -d '(' -f1`
var3=`echo $line|cut -d '=' -f2`
var2=`grep $var1  newfile`
#var3=`echo $line|cut -d '=' -f2`
#echo $var2
tmp=`echo $var2|cut -d '<' -f1`
echo "$tmp"  >>outfile1.html
tmp1=`echo "</td><td>$var3 $var</td>"`
echo $tmp1 >>outfile1.html
tmp2=`echo $var2|cut -d '<' -f3-10`
    echo "<$tmp2" >>outfile1.html
    echo "</td>" >>outfile1.html
    #echo "stats rep1 , table $line , daily" | ./ggsci > $logpath/$var.txt
    done < /home/ggowner/ODI_MONITORING/scenario.txt
    echo "</tr></table>" >>outfile1.html
    }

    send_mail()
    {
    #export MAILTO="$emailTo"
    #export CONTENT="$outfile"
    #export SUBJECT="Subject"

    (
    echo "From: ODIDailyMon@techmahindra.com"
    echo "To: $emailTo"
    echo "Subject: ODI Monitoring_`date +%d%m%y`"
    echo "MIME-Version: 1.0"
    echo "Content-Type: text/html"
    echo "Content-Disposition: inline"

    #cat $logFile2
    cat outfile1.html

    ) | /usr/sbin/sendmail -t
    }
    emailTo="monica.tent0@bt.com "
    odi_monitoring.sh
    prepare_HTML
    send_mail

    find . -name "roch_snpsession_*"  -mtime +10 |xargs rm -f
Amit
  • 41
  • 1
  • 6
  • i assume that you are trying to read the file `/home/ggowner/ODI_MONITORING/scenario.txt` in the `while` loop,so better you could try this:`ls /home/ggowner/ODI_MONITORING/scenario.txt |while read line done` – User123 Apr 22 '18 at 13:19
  • Perhaps you should reduce things to a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/). Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Apr 22 '18 at 14:33

0 Answers0