我想在UNIX下实现下面的功能:   1、编写一个       TEST.SH脚本   
    
        .sh的       功能如下:   
        访问数据库的       某个表       tableName,如果有满足条件的记录则将记录输出到文本out.txt,   
        并将out.txt以附件的方式发送邮件到指定的邮箱   
        否则什么都不做。   
        
ORACLE数据库     
USERNAME:DATA_USER   
SID       :SID_NAME   
PASSWORD       :PASSWORD   
2、让TEST.sh       脚本       一天执行两次       (周一到周五       每天早上8点,下午5点       );   各位老大帮帮忙了 。

解决方案 »

  1.   

    你还是用job驱动一个java或c的存储过程吧……
      

  2.   

    test.sql
      spool 123.txt
      select * from tableName;
      spool off;
      //调用oracle Mail包发送指定的邮箱里  //调用oracle job包,指定执行的时间
      

  3.   

    访问数据库的某个表 tableName,如果有满足条件的记录则将记录输出到文本out.txt
    用shell单独可以做到吗?先去查询,等返回回来的东西然后再判断
    需要跟你平台相关吧?用存储过程或者你平台语言写一个就好。每天定时,你直接用crontab就可以
      

  4.   

    1: spool .. sqlplus .. mailx ..2: crontab .. 1-5 .. 
      

  5.   

    请问楼上的大哥,
    怎么调用oracle   Mail包发送指定的邮箱里 啊?
      

  6.   

    1.发送邮件直接用unix 或linux 操作系统的吧,比使用oracle要方便快捷的多。
      下面命令会发送标题为“subject",邮件内容为 context.txt 文本内容,带有附件 attachment 的邮件到mailaddress
      cat  content.txt |  mailx -a attachment -s "subject"  mailaddress
    2.定时作业的话直接用crontab 好了。
    例如:
    --test.shcd $HOME
    .  ./.profilecd  test
    sqlplus /nolog  @query.sql  if  [ -s  result.txt ] 
    then
    cat result.txt >> head.txt 
    echo "test" | mailx -a head.txt -s "SUBJECT"  [email protected]
    fi--query.sql
    connect /  as sysdba;
    set head on
    set feedback off
    set pages 100
    set lines 120
    set wrap on
    set ver off
    spool head.txt
    select *  from  tableaname where 1=2 ;
    spool off
    set head off
    spool result.txt
    select *  from  tableaname where <your search condition> ;
    spool off
    exit
      

  7.   

    最近刚整理了一篇“ 浅谈sql输出及变量输入及传递 ”,大家有兴趣的话可以看看。摘要:本文从笔者采用的监控表空间的程序例子出发,介绍了如何shell 和sql 结合实现某些监控等需求,sql的结果输出以及sql 中变量的获取和相互传递等,大致总结了几种常用的sql变量获取和传递的方式。例子中还穿插了一小段定时自动得到statspack 报告的程序,这个在后面的文章中再总结。 
     http://blog.csdn.net/kongkongye/archive/2008/02/05/2084196.aspx
      

  8.   

    感谢kongkongye在新春之中抽时间答疑解惑,
    用的给出 的方法输出到文件已经成功了 ,关键的是邮件发送失败
    我的test.sh 如下:
    --test.sh cd   $HOME 
    ../profile cd     /oradata/rp_data/test
    sqlplus   /nolog     @query.sql     if [-s result.txt]   
    then 
    cat   result.txt >>head.txt   
    echo   "test" |mail  -a  head.txt  -s  "SUBJECT"  [email protected] 
    fi
    执行结果如下:[oracle@jsyyfx test]$ ./test4.sh
    ./test4.sh: line 2: ../profile: 没有那个文件或目录SQL*Plus: Release 9.2.0.4.0 - Production on Thu Feb 14 12:54:14 2008Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.Connected.200712   G                            0                               268160           6.88    1309979          -10.28
           356111           .32     899713         -12.82     210635         118244 9962805.37           1.17 2321835.23
              3.64 7640970.14           .45        186       1.09        162        -1.82        87.1            -2.87
            24       5012           -9.99       1551         -24.56         30.95             -16.19        3461200712   L                            0                              1234067          -5.56    2772747            -2.5
          1487656          2.69    1212530          -7.84     752940         345209 14408452.2          -1.95 8335812.23
               .83 6072639.95         -5.53         86       1.18         75            0       87.21            -1.17
            11       1605           -1.11       1128          -2.34         70.28              -1.24         477200712   T       29492600           .26      1202172      1126794    1416438          -4.33    3637798           -5.14
          1726255          1.88    1939673         -10.39     940097         397560 24371257.6            -.7 10657647.5
              1.43 13713610.1         -2.29        272       1.12        237        -1.25       87.13            -2.34
            35       6617           -7.98       2679         -16.57         40.49              -9.32        3938Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.4.0 - Production
    ./test4.sh: line 7: [-s: command not found
    出错如下:
    ./test4.sh: line 2: ../profile: 没有那个文件或目录
    ----这个profile:是 我的权限不够吗?./test4.sh: line 7: [-s: command not found
    ----这个是说我 的邮件发送不 对吗?
    谢谢你了 
      

  9.   

    1.  你写错了, 两个点之间有空格,意思是将当前目录下的.profile文件执行一下,将其中的环境变量读取过来。这是我写shell 的习惯,好像也没多大必要。如果你要用,要确认你用的是否是 .profile,或者是其他名称。 
    .   ./.profile 
    2.对于发邮件,没有看到你的sh 脚本中有mailx 命令啊,那怎么发邮件?
      

  10.   

    --test.sh 如下:  cd       $HOME   
    ../profile   cd           /oradata/rp_data/test 
    sqlplus       /nolog           @query.sql           if   [-s   result.txt]       
    then   
    cat       result.txt   > > head.txt       
    echo       "test"   ¦mail     -a     head.txt     -s     "SUBJECT"     [email protected]   
    fi 
    --由于是LINUX 所以用的是 MAIL 而不是MAILX指令
    但我用MAIL指令发邮件给我自己的时候从来都没有收到过,
    我等下把邮件发送日志截取出来给你看看,看能不能解决。
    谢谢你了。