ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle报表自动FTP脚本

oracle报表自动FTP脚本

原创 Linux操作系统 作者:skuary 时间:2011-04-20 14:23:51 0 删除 编辑

日常工作中每天自动任务跑的各种报表或者备份,需要定期上传到指定的FTP服务器的话,就可以用下面的脚本来实现

AUTHSTATE=compat
export SHELL=/usr/local/bin/bash
export NLS_LANG=American_America.ZHS16GBK
export PATH=/opt/softbench/bin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/usr/contrib/Q4/bin:/opt/perl/bin:/opt/ipf/bin:/opt/hparray/bin:/opt/nettladm/bin:/opt/fcms/bin:/opt/sas/bin:/opt/wbem/bin:/opt/wbem/sbin:/usr/bin/X11:/opt/resmon/bin:/opt/perf/bin:/usr/contrib/kwdb/bin:/opt/graphics/common/bin:/opt/prm/bin:/opt/sfm/bin:/opt/hpsmh/bin:/opt/upgrade/bin:/opt/wlm/bin:/opt/gvsd/bin:/opt/sec_mgmt/bastille/bin:/opt/drd/bin:/opt/dsau/bin:/opt/dsau/sbin:/opt/firefox:/opt/gnome/bin:/opt/mozilla:/opt/perl_32/bin:/opt/perl_64/bin:/opt/sec_mgmt/spc/bin:/opt/ssh/bin:/opt/swa/bin:/opt/thunderbird:/opt/gwlm/bin:/usr/contrib/bin/X11:/opt/aCC/bin:/opt/caliper/bin:/opt/cadvise/bin:/opt/sentinel/bin:/opt/langtools/bin:/usr/sbin:/usr/local/sbin:/sbin:/oramem/oracle/product/10.2.0/bin:/usr/local/bin:/home/oracle/bin:/usr/sbin:/usr/local/sbin:/sbin
export BASH_ENV=/home/sunyuke/.bashrc
export ORACLE_HOME=/oramem/oracle/product/10.2.0
export NLS_DATE_FORMAT=YYYYMMDDHH24MISS
export NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
export LD_LIBRARY_PATH=/oramem/oracle/product/10.2.0/lib:/oramem/oracle/product/10.2.0/sqlplus/lib:/usr/lib:/lib:
cd /tmp/kpi_sh/dong/
./get_date.sh
export yestday=`cat yest_date.txt `
tar cvf ./pass9_$yestday ./*_$yestday\000000_`date +%Y%m%d`\000000*.txt
gzip ./pass9_$yestday
userName=username
ftpIP=xx.xx.xx.xx
pwd=passwd
srcDir=/tmp/kpi_sh/dong/
yy=`date +%Y`;mm=`date +%m`;dd=`date +%d`
d0=`echo "$dd"|awk '{printf"%02d\n",$1-1}'`
m0=`echo "$mm"|awk '{printf"%02d\n",$1-1}'`
y0=`echo "$yy"|awk '{printf"%02d\n",$1-1}'`
case $d0 in
00) if [ $m0 = 00 ]; then
    ym=`cal 12 $y0|xargs|awk '{print $NF}'`
    y0=$y0;m0=12;d0=$ym
    else
    ym=`cal $m0 $yy|xargs|awk '{print $NF}'`
    d0=$ym;m0=$m0;y0=$yy
    fi
    ;;
*) d0=$d0;m0=$mm;y0=$yy;;
esac
destDir=/ETL
fileName1=pass9_$yestday.gz
fileName2=sg2_active_day_$yestday.txt
function ftp_files {
if [ -f ${1}/${2} ];then
 echo "===> 文件传送到$ftpIP:路径$3 ...
        原文件目录: $1
        原文件名: $2
        目标文件路径: $3 "
         echo " user $userName $pwd
           lcd $1
             cd $3
            bin
               put  $2
                 bye" |ftp -n $ftpIP
                 else
                   echo "$fileName not exists"
                   fi
                   }

                   ftp_files $srcDir $fileName1 $destDir
                   ftp_files $srcDir $fileName2 $destDir
                                                                                                                            ftp_files $srcDir $fileName3 $destDir
 ftp_files $srcDir $fileName4 $destDir
ftp_files $srcDir $fileName5 $destDir
ftp_files $srcDir $fileName6 $destDir
ftp_files $srcDir $fileName7 $destDir
ftp_files $srcDir $fileName8 $destDir
ftp_files $srcDir $fileName9 $destDir
ftp_files $srcDir $fileName10 $destDir
rm -rf ./*_$yestday\000000_`date +%Y%m%d`\000000*.txt
#rm -rf ./pass9_$yestday.gz

感觉蛮有用的,记录一下。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25618347/viewspace-713834/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-03-31

  • 博文量
    88
  • 访问量
    317070