sqlldr从数据库获取数据并上传到服务器

1、需求:

 sqlldr从数据库获取数据并上传到服务器


2、查询目标数据的sql语句文件(INTERFACE_test_RESULT.sql),文件里内容如下:

SELECT name, age from emp;


3、执行sh脚本(INTERFACE_RESULT.sh),文件里内容如下:

#!/bin/bash
. $HOME/.bash_profile

export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
v_out_path="/test_out/test/test_return_data"
v_out_file="test_order_"`date "+%Y%m%d"`


echo "deal old file"
cd $v_out_path
#rm -rf $v_out_path/*.txt
#mv $v_out_path/*.txt $c_out_path/data_backup/
#mv *.txt data_backup/


cd /test_out/test/test_sqlldr/
echo "spool begin..."
sqlplus -s test_out/test_out@127.12.12.12:1521/wxclyy<<EOF
set trimspool on
set linesize 120
set pagesize 0
set newpage 1
set heading off
set term off
set feedback off
--update tbl_interface_export_result set f_result = substr(f_result,1,2);
--commit;
--exec prc_data_4g_yupan;
spool $v_out_path/$v_out_file.txt
@INTERFACE_test_RESULT.sql;
spool off
exit;
EOF
echo "spool end..."
sed -i '/^$/d' $v_out_path/$v_out_file.txt
echo "del null row.."

#ftp 开始
#如果需要通过ftp上传到别的服务器,则使用以下脚本,如果只是当前sh脚本所有服务器,则不需要以下脚本
ftpserver=127.0.0.1

#指定的是用户名test,密码test
echo "user test test" > test_order_ftp.txt
echo "bin" >> test_order_ftp.txt
echo "put $v_out_path/$v_out_file.txt $v_out_file.txt" >> test_order_ftp.txt
echo "bye" >> test_order_ftp.txt

ftp -n $ftpserver < test_order_ftp.txt

#ftp 结束


#cp $v_out_path/$v_out_file.txt $v_out_path/data_backup/
#echo "file backup.."
echo "End time: "`date "+%Y-%m-%d %H:%M:%S"`


4、如果有ftp上传,则还需要以下文件test_order_ftp.txt

user test test
bin
put /test_out/test/test_return_data/test_call_20170812.txt test_call_20170812.txt
bye


5、执行sh脚本

   ./INTERFACE_RESULT.sh



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值