#一个从网上自动下载指定文件并入库的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
#删除以前的表记录
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博客 ” ,链接:https://blog.itpub.net/26143577/viewspace-720227/
,如需转载,请注明出处,否则将追究法律责任。