while循环在shell脚本中不起作用

时间:2018-04-22 12:41:58

标签: linux shell unix

我想在代码下面将.csv文件转换为HTML格式。在脚本中没有执行while循环。while被忽略,控件直接转到最后一行.newfile包含从a生成的数据SQL查询。 .csv文件已被重定向到newfile。 请在下面找到代码。

    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

0 个答案:

没有答案