写个shell脚本连接oracle数据库查询某表数据导出为txt文件,再发送到第三
写个shell脚本连接oracle数据库查询某表数据导出为txt文件,再发送到第三方服务器,谢谢...
写个shell脚本连接oracle数据库查询某表数据导出为txt文件,再发送到第三方服务器,谢谢
展开
展开全部
1、简单的单列
#!/bin/sh
sqlplus 'user001/12345678'<< EOF
set define off
set hea off
spool vip1.txt
select username from ACCOUNT where LEVEL=7;
spool off
quit;
EOF
sed -i 's/[ ]*//g' ~/vip1.txt
sed -i '/^$/d' ~/vip1.txt
sed -i '1d' ~/vip1.txt
sed -i '$d' ~/vip1.txt
scp -P22 ~/vip1.txt root@172.16.1.2:/root
2、复杂的多列
#!/bin/sh
cid=$1;
today=`date +%Y-%m-%d-%H.%M`
ym=`date +%Y%m`
ymd=`date -d -1days +%Y%m%d`
last_ym=`date -d last-month +%Y%m`
next_ym=`date -d next-month +%Y%m`
file=chat_recorder_${cid}_20140707-11.xls
if [[ $1 == '' ]];then
echo "Usage: $0 company_id "
exit 0;
fi
sqlplus 'user002/12345678' << EOF
set linesize 200
set term off verify off feedback off pagesize 999
set markup html on entmap ON spool on preformat off
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
spool ${file}
select a.*,b.* from recorder_${ym} a,t_${ym} b where a.company_id='$cid' and a.create_time between TO_DATE('2014-07-07 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2014-07-12 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and a.chat_id=b.chat_id order by b.chat_id ;
spool off
quit;
EOF
sed -i '/select/d' $file
zip -r ${file}.zip $file
scp -P22 ${file}.zip root@172.16.1.5:/opt
#!/bin/sh
sqlplus 'user001/12345678'<< EOF
set define off
set hea off
spool vip1.txt
select username from ACCOUNT where LEVEL=7;
spool off
quit;
EOF
sed -i 's/[ ]*//g' ~/vip1.txt
sed -i '/^$/d' ~/vip1.txt
sed -i '1d' ~/vip1.txt
sed -i '$d' ~/vip1.txt
scp -P22 ~/vip1.txt root@172.16.1.2:/root
2、复杂的多列
#!/bin/sh
cid=$1;
today=`date +%Y-%m-%d-%H.%M`
ym=`date +%Y%m`
ymd=`date -d -1days +%Y%m%d`
last_ym=`date -d last-month +%Y%m`
next_ym=`date -d next-month +%Y%m`
file=chat_recorder_${cid}_20140707-11.xls
if [[ $1 == '' ]];then
echo "Usage: $0 company_id "
exit 0;
fi
sqlplus 'user002/12345678' << EOF
set linesize 200
set term off verify off feedback off pagesize 999
set markup html on entmap ON spool on preformat off
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
spool ${file}
select a.*,b.* from recorder_${ym} a,t_${ym} b where a.company_id='$cid' and a.create_time between TO_DATE('2014-07-07 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2014-07-12 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and a.chat_id=b.chat_id order by b.chat_id ;
spool off
quit;
EOF
sed -i '/select/d' $file
zip -r ${file}.zip $file
scp -P22 ${file}.zip root@172.16.1.5:/opt
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询