日期:2014-05-16  浏览次数:20634 次

linux 文件入库脚本
----linux文件入库脚本
#!/bin/bash
#一个输入参数时间,格式为yyyymmdd,不输入时,使用系统前一天日

if [ ${#1} -eq 6 ] ; then
day=$1
else
day=$(date -d "" +%Y%m)
fi

if [ ${#1} -eq 6 ] ; then
day1=$2
else
day1=$(date -d "1 month ago" +%Y%m)
fi
source /home/oracle/.bash_profile

file_name=/oradata/org_data/ftp_down/itv/login/itv_login.ctl

echo "LOAD DATA">$file_name
ls /oradata/org_data/ftp_down/itv/login/ |grep "$day" | while read -a line
do
echo "INFILE  \"/oradata/org_data/ftp_down/itv/login/${line[0]}\" \"str'\\r\\n'\"">>$file_name
done
echo "INTO TABLE ITV_LOGIN_M">>$file_name
echo "APPEND">>$file_name
echo "FIELDS TERMINATED BY '|'">>$file_name
echo "TRAILING NULLCOLS ">>$file_name
echo "( ">>$file_name
echo "WIDTHID,">>$file_name
echo "USERID,">>$file_name
echo "CREATEDATE,">>$file_name
echo "LOGINTIMES,">>$file_name
echo "VIEWMINUTS,">>$file_name
echo "LEIXING,">>$file_name
echo "MONTH CONSTANT "$day1"">>$file_name
echo ")">>$file_name

sqlldr  userid=username/passwd control=$file_name log=/oradata/org_data/ftp_down/itv/login/log/itvlogin_$day.log errors=600000000 direct=Y