激情五月天婷婷,亚洲愉拍一区二区三区,日韩视频一区,a√天堂中文官网8

<ul id="buwfs"><strike id="buwfs"><strong id="buwfs"></strong></strike></ul>
    <output id="buwfs"></output>
  • <dfn id="buwfs"><source id="buwfs"></source></dfn>
      <dfn id="buwfs"><td id="buwfs"></td></dfn>
      <div id="buwfs"><small id="buwfs"></small></div>
      <dfn id="buwfs"><source id="buwfs"></source></dfn>
      1. <dfn id="buwfs"><td id="buwfs"></td></dfn>
        始創(chuàng)于2000年 股票代碼:831685
        咨詢(xún)熱線(xiàn):0371-60135900 注冊(cè)有禮 登錄
        • 掛牌上市企業(yè)
        • 60秒人工響應(yīng)
        • 99.99%連通率
        • 7*24h人工
        • 故障100倍補(bǔ)償
        全部產(chǎn)品
        您的位置: 網(wǎng)站首頁(yè) > 幫助中心>文章內(nèi)容

        Linux下Oracle查詢(xún)結(jié)果以html格式定期發(fā)送郵件

        發(fā)布時(shí)間:  2012/9/24 16:49:59

        任務(wù): 每天早上8:00將Oracle查詢(xún)語(yǔ)句的內(nèi)容變成html的形式,制作一腳本,在指定時(shí)間用mutt自動(dòng)發(fā)送到郵箱

        版本: Linux version 2.6.18-194.el5

        Oracle Release 10.2.0.5.0-
         


        使用工具:shell 腳本

        mutt 郵件代理

        sendmail

        crontab 自動(dòng)任務(wù)處理

         

        一 shell腳本(生成html文件,mutt發(fā)送)

        1 生成html文件

        利用行列轉(zhuǎn)換的sql語(yǔ)句,將sys用戶(hù)下的tb表(表-1)形式轉(zhuǎn)化為表-2,并生成html1.html文件

        表-1

        NAME       COURSE          SCORE
        ---------- ---------- ----------
        chen       chinese            74
        chen       math                 99
        chen       physics            88
        ck          chinese            78
        ck          math                 89
        ck          physics            98

        表-2
        NAME                     chinese              math         physics            totle                avg
        ---------- ---------- ---------- ---------- ---------- ----------
        chen                              74                  99                 88                261                  87
        ck                                 78                  89                 98                265              88.33


        使用的select語(yǔ)句(行列轉(zhuǎn)換)

        select name,sum(decode(course,'chinese',score,0)) "chinese",sum(decode(course,'math',score,0)) "math",sum(decode(course,'physics',score,0)) "physics",sum(score) "totle",round(avg(score),2) "avg" from tb group by name;

         

         

        生成html文件

        #設(shè)置生成表格式


        set pagesize 0

        set term off

        set feedback off

        set linesize 1000

        set trimspool on

        set term off verify off feedback off pagesize 999     


        #開(kāi)啟生成html文件


        set markup html on entmap on spool on head "<TITLE>Grade of Students</title> <!--body {backgroud:ffffc6} --></style>"

        set echo off

        spool /home/Oracle/html1.html replace

        select name,sum(decode(course,'chinese',score,0)) "chinese",sum(decode(course,'math',score,0)) "math",sum(decode(course,'physics',score,0)) "physics",su m(score) totle,round(avg(score),2) avg from tb group by name;

        spool off

        set markup html off

        set echo on


        2 使用mutt發(fā)送

        echo cklovely@vip.qq.com > /tmp/user.txt --需要發(fā)送的郵件

        echo “test”|mutt -s “subject name” -a /home/Oracle/html1.html `cat /tmp/user.txt`

         


        說(shuō)明:-s 郵件的題目 -a 添加附件 最后是添加發(fā)送的郵箱地址

         


        注意:此處默認(rèn)發(fā)件箱是本機(jī) root@localhost.localdomain,而值得一提的是,必須要在sendmail運(yùn)行的行況下才可以發(fā)送

          a   關(guān)于sendmail啟動(dòng)緩慢的問(wèn)題

            這是個(gè)比較常見(jiàn)的問(wèn)題,出現(xiàn)這個(gè)問(wèn)題的根本原因是主機(jī)名沒(méi)有分配好

        解決辦法:

            我們可以修改系統(tǒng)配置文件/etc/hosts 和/etc/resolv.conf

            讓sendmial繞過(guò)查詢(xún)遠(yuǎn)程主機(jī),這里給出一種最簡(jiǎn)單的方法,給主機(jī)設(shè)置一個(gè)別名

                修改/etc/hosts ,未修改之前

             127.0.0.1 localhost.localdomain localhost

                修改成

             127.0.0.1 localhost.localdomain localhost cklovely

         


          b    如果不需要從 root@localhost.localdomain 中發(fā)送郵件,可以選擇從哪個(gè)郵箱發(fā)送,在/etc/Muttrc中添加一行

             my_hdr from: ckQyanqi@126.com

         


        3 完成html.sh腳本

        cat /home/Oracle/html.sh

        #!/bin/bash

        source ~Oracle/.bash_profile

        $Oracle_HOME/bin/sqlplus -s "/ as sysdba" <<E

        set pagesize 0

        set term off

        set feedback off

        set linesize 1000

        set trimspool on

        set term off verify off feedback off pagesize 999

        set markup html on entmap on spool on head "<TITLE>Grade of Students</title> <!--body {backgroud:ffffc6} --></style>"

        set echo off

        spool /home/Oracle/html1.html replace

        select name,sum(decode(course,'chinese',score,0)) "chinese",sum(decode(course,'math',score,0)) "math",sum(decode(course,'physics',score,0)) "physics",sum(score) totle,round(avg(score),2) avg from tb group by name;

        spool off

        set markup html off

        set echo on

        E

        echo cklovely@vip.qq.com > /tmp/user.txt

        echo "test"|mutt -s "Grade of Students" -a /home/Oracle/html1.html `cat /tmp/user.txt`

         


           二   系統(tǒng)自動(dòng)按時(shí)發(fā)送

            定義時(shí)間讓系統(tǒng)自動(dòng)運(yùn)行腳本的方法很多

            而在linux系統(tǒng)中經(jīng)常使用的要數(shù)crontab了。

            (其他的方法有:Oracle中的dbms_jobs,還有就是dbms_scheduler)

            /etc/cron.deny:
               將不可以使用 crontab 的帳號(hào)寫(xiě)入其中,若未記錄到這個(gè)檔案當(dāng)中的使用者,就可以使用 crontab 。

         


            運(yùn)行crontab有2種方法:

           1 直接用crontab命令

            當(dāng)使用者使用 crontab 這個(gè)指令來(lái)建立工作排程之後,該項(xiàng)工作就會(huì)被紀(jì)錄到 /var/spool/cron/ 裡面去了,而且是以帳號(hào)來(lái)作為判別的。另外, cron 執(zhí)行的每一項(xiàng)工作都會(huì)被紀(jì)錄到 /var/log/cron 這個(gè)登錄檔中,所以囉,如果你的 Linux 不知道有否被植入木馬時(shí),也可以搜尋一下 /var/log/cron 這個(gè)登錄檔呢!

            Crontab語(yǔ)法:

             crontab [-u username] [-l|-e|-r]

             croutab -e (默認(rèn)username為root)打開(kāi)/var/spool/cron/root 編輯

             croutab -l (默認(rèn) username 為root)查看root用戶(hù)下的自動(dòng)任務(wù)

             croutab -r (默認(rèn) username 為root)刪除root下所有的自動(dòng)任務(wù)

            編輯內(nèi)容:

               * * * * * command

         


        代表意義 分鐘 小時(shí) 日期 月份 週 指令
        數(shù)字範(fàn)圍 0-59 0-23 1-31 1-12 0-7 命令或腳本


        特殊字符 代表意義
        *(星號(hào)) 代表任何時(shí)刻都接受的意思!舉例來(lái)說(shuō),範(fàn)例一內(nèi)那個(gè)日、月、週都是 * , 就代表著『不論何月、何日的禮拜幾的 12:00 都執(zhí)行後續(xù)指令』的意思!
        ,(逗號(hào)) 代表分隔時(shí)段的意思。舉例來(lái)說(shuō),如果要下達(dá)的工作是 3:00 與 6:00 時(shí),就會(huì)是:
        0 3,6 * * * command
        時(shí)間參數(shù)還是有五欄,不過(guò)第二欄是 3,6 ,代表 3 與 6 都適用!
        -(減號(hào)) 代表一段時(shí)間範(fàn)圍內(nèi),舉例來(lái)說(shuō), 8 點(diǎn)到 12 點(diǎn)之間的每小時(shí)的 20 分都進(jìn)行一項(xiàng)工作:
        20 8-12 * * * command
        仔細(xì)看到第二欄變成 8-12 喔!代表 8,9,10,11,12 都適用的意思!
        /n(斜線(xiàn)) 那個(gè) n 代表數(shù)字,亦即是『每隔 n 單位間隔』的意思,例如每五分鐘進(jìn)行一次,則:

        */5 * * * * command
        很簡(jiǎn)單吧!用 * 與 /5 來(lái)搭配,也可以寫(xiě)成 0-59/5 ,相同意思!

           2 系統(tǒng)設(shè)定文件:/etc/crontab 必須是root用戶(hù)設(shè)定

          * MAILTO=root:
        這個(gè)項(xiàng)目是說(shuō),當(dāng) /etc/crontab 這個(gè)檔案中的例行性工作的指令發(fā)生錯(cuò)誤時(shí),或者是該工作的執(zhí)行結(jié)果有 STDOUT/STDERR 時(shí),會(huì)將錯(cuò)誤訊息或者是螢?zāi)伙@示的訊息傳給誰(shuí)

            例如 MAILTO=cklovely@vip.qq.com

          * PATH=....

            這里就是輸入執(zhí)行命令的搜索路徑,使用預(yù)設(shè)定路徑已經(jīng)足夠了

          * 01 * * * * root run-parts /etc/cron.hourly;

            注意:但是在五個(gè)時(shí)間后面接的並不是指令,而是一個(gè)新的位置,那就是『執(zhí)行後面那串指令的身份』,這與使用者的 crontab -e 不相同

         


            基本上, cron 這個(gè)服務(wù)的最低偵測(cè)限制是『分鐘』,所以『 cron 會(huì)每分鐘去讀取一次 /etc/crontab 與 /var/spool/cron 裡面的資料內(nèi)容 』,因此,只要你編輯完 /etc/crontab 這個(gè)檔案,並且將他儲(chǔ)存之後,那麼 cron 的設(shè)定就自動(dòng)的會(huì)來(lái)執(zhí)行了!

            當(dāng)然,也可以用service crond restart

         


         例如本例

        方法一:

            crontab -e

            00 08 * * * su – Oracle -c “/home/oracle/html.sh”

        方法二:

            vi /etc /crontab

            00 08 * * * root su – Oracle -c “/home/oracle/html.sh”

        或者

            00 08 * * * Oracle /home/oracle/html.sh


         


        本文出自:億恩科技【mszdt.com】

        服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

      2. 您可能在找
      3. 億恩北京公司:
      4. 經(jīng)營(yíng)性ICP/ISP證:京B2-20150015
      5. 億恩鄭州公司:
      6. 經(jīng)營(yíng)性ICP/ISP/IDC證:豫B1.B2-20060070
      7. 億恩南昌公司:
      8. 經(jīng)營(yíng)性ICP/ISP證:贛B2-20080012
      9. 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話(huà):0371-60135900
      10. 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話(huà):0371-60135900
      11. 專(zhuān)注服務(wù)器托管17年
        掃掃關(guān)注-微信公眾號(hào)
        0371-60135900
        Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號(hào)總部企業(yè)基地億恩大廈  法律顧問(wèn):河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號(hào)
          0
         
         
         
         

        0371-60135900
        7*24小時(shí)客服服務(wù)熱線(xiàn)