#!/usr/bin/bash
datefile=$1
work_path=$2
start_time=`date +%Y%m%d%H%M%S`
#work_path=/home/oracle/fk_data
#数据库信息
DbCon=**********
file_date=`date +%Y%m%d`
filename=${work_path}/"$datefile"_${file_date}.txt
sqlinfo="select * from $datefile;"
echo "执行的sql: $sqlinfo"
echo "---------------- start to exec job $start_time "
echo "---------------- connect to $DbCon and try to exec sql..."
sqlplus -S $DbCon<< EndSql
#行最大字符数
set line 20000
set pagesize 0
set feedback off
set heading off
set trimspool on
set trims on
set echo off
set colsep '|'
--set termout off
spool $filename
#这个地方写你想要查询的SQL
spool off
exit
EndSql
#去除文件开头的空格及中间的空白字符
sed -i 's/ //g' ${work_path}/"$datefile"_${file_date}.txt
end_time=`date +%Y%m%d%H%M%S`
echo "---------------- cmd end , please check te result $end_time"
Linux数据抽取shell脚本
最新推荐文章于 2022-10-05 15:56:46 发布