ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 网页文件自动下载入库脚本_shell_sqlldr

网页文件自动下载入库脚本_shell_sqlldr

原创 Linux操作系统 作者:YallonKing 时间:2012-04-02 19:13:43 0 删除 编辑
#一个从网上自动下载指定文件并入库的shell脚本。
#!/bin/bash
# ############################################################################
#
#                    created by yallonking
#
#                    2012-4-2  zxbp.sh
#
#                    Email:oraking_job@163.com
#
# ############################################################################
ORACLE_SID=m1hf; export ORACLE_SID
ORACLE_BASE=/m1hf; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/oracle; export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH; export PATH
NLS_LANG="Simplified Chinese_china".ZHS16GBK; export NLS_LANG
PATH=$PATH:$HOME/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH
#获取文件
wget -t 5 "http://202.108.253.184/csvsave.asp?spcode=SH816000" -O /opt/wyl/downloads/SH816000_`date +%Y%m%d`.txt -o /opt/wyl/sqlldr/logs/SH816000_`date +%Y%m%d`.log
wget -t 5 "http://202.108.253.184/csvsave.asp?spcode=SH818100" -O /opt/wyl/downloads/SH818100_`date +%Y%m%d`.txt -o /opt/wyl/sqlldr/logs/SH818100_`date +%Y%m%d`.log
wget -t 5 "http://202.108.253.184/csvsave.asp?spcode=SH818200" -O /opt/wyl/downloads/SH818200_`date +%Y%m%d`.txt -o /opt/wyl/sqlldr/logs/SH818200_`date +%Y%m%d`.log
wget -t 5 "http://202.108.253.184/csvsave.asp?spcode=SH818300" -O /opt/wyl/downloads/SH818300_`date +%Y%m%d`.txt -o /opt/wyl/sqlldr/logs/SH818300_`date +%Y%m%d`.log
#删除以前的表记录
sqlplus /nolog<conn username/password
truncate table idx.idxzxbpquoteday_bak;
exit;
eof
#文件入库
file_in=/opt/wyl/downloads/
dos2unix /opt/wyl/downloads/*
file_temp=/opt/wyl/sqlldr/file_temp
for file_a in ${file_in}/*; do
    cp $file_a $file_temp/test.csv
    filename=`basename $file_a`
    sqlldr username/password control=/opt/wyl/sqlldr/zxbp.ctl bad=/opt/wyl/sqlldr/zxbp.bad  log=/opt/wyl/sqlldr/test.log  direct=true
    rm -rf $file_temp/*
    mv /opt/wyl/sqlldr/test.log /opt/wyl/sqlldr/logs/$filename
done
rm -rf /opt/wyl/downloads/*
#取消记录中多余引号,并去掉重复记录行
sqlplus /nolog<conn username/password
truncate table idx.idxzxbpquoteday;
drop table idx.idxzxbpquoteday;
create table idx.idxzxbpquoteday as select trim('"' from secucode) as secucode,
trim('"' from secuname) as secuname,
tradingday,
openprice,
highprice,
lowprice,
closeprice,
turnovervolume,
turnovervalue
from idx.idxzxbpquoteday_bak;
delete from idx.idxzxbpquoteday where rowid in
(select a.rowid from idx.idxzxbpquoteday a,idx.idxzxbpquoteday b
where a.rowid > b.rowid
and a.secucode=b.secucode
and a.secuname=b.secuname
and a.tradingday=b.tradingday
and a.openprice=b.openprice
and a.highprice=b.highprice
and a.lowprice=b.lowprice
and a.closeprice=b.closeprice
and a.turnovervolume=b.turnovervolume
and a.turnovervalue=b.turnovervalue);
commit;
SELECT TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS') FROM DUAL;
select max(tradingday) as table_last_updateday from idx.idxzxbpquoteday;
exit;
eof
 
#在crontab中制定此脚本执行计划即可!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26143577/viewspace-720227/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-08-07

  • 博文量
    72
  • 访问量
    246048