自动转发报表shell程序

    技术2022-05-11  131

    每天省中心做完批处理之后,生成每个网点的报表,需要分发到各个网点,将报表放到其所属联社银行前置机上,此程序就是用来自动转发报表,在Linux中设定任务,在固定的时候发送到各联社前置机上程序由三部分组成:man_dispense             rpt_dispense.cfg                rpt_dispense.shman_dispense     -- 根据rpt_dispense.sh和rpt_dispense.cfg组合一些参数信息rpt_dispense.cfg  -- 用来存储各联社前置机登陆密码,一些配置表rpt_dispense.sh   -- 运行主shell程序rpt_dispense.cfg内容111 user1  pwd1  ip1/host1         #联社1   联社号  用户名   密码   ip地址/host名字222 user2  pwd2  ip2/host2         #联社2333 user3  pwd3  ip3/host3         #联社3rpt_dispense.sh代码#!/bin/ksh#使用方法 sh rpt_dispense.sh 20040808(date)if [ $# -lt 1 ]then    echo "使用方法 sh rpt_dispense.sh 20040808"    exit 1fidate=$1                                         #把第一个参数赋值给date变量(1)echo "开始下发"while read line                                 #按行读取一行,放入到line变量中do    echo "开始下发"    echo $cd                                    #显示联社号    cd=`echo $line|cut -d " " -f1`              #此行按" "(一个空格)分隔的第一个参数    user=`echo $line|cut -d " " -f2`            #第二个为用户名,`在1左边,表示执行    passwd=`echo $line|cut -d " " -f3`          #第三个为密码    host=`echo $line|cut -d " " -f4`            #第四个为HOST/IP    #运行man_dispense程序,参数带入,并且指定错误日志,&表示后台运行    sh man_dispense $cd $user $passwd $host $date 1>>rpt.log 2>>rpt.err &    sleep 5                                     #系统等待5秒done <rpt_dispense.cfg                          #输入文本为rpt_dispense.cfgman_dispense代码#!/bin/ksh#This program is for auto tar the rpt,and use ftp to send the file. #You have to manual enter the date of rpt which you want.cd=$1                                  #第一个参数为联社号user=$2                                #第二个参数为用户名passwd=$3                              #第三个参数为密码host=$4                                #第四个参数为HOST名字/IP地址d=$5                                   #第五个参数为日期filename=$1_$5                         #需要打包的文件名为 联社号_日期cd /rptpath                            #到报表路径位置tar cf rpt_$filename.tar ./$cd*/*$d*   #tar成包,不加参数v显示gzip -f rpt_$filename.tar              #压缩此tar文件

    ftp -ni <<+                            #采用命令方式使用FTP,类似sqlplus <<!  ... !open $host                             #连接到hostuser $user $passwd                     #用户名密码umask 000                              #待查ftp命令bin                                    #采用二进制传输cd /rptpath                            #进入远端报表路径put rpt_$filename.tar.gz               #上传文件bye                                    #断开连接+                                      #FTP命令结束

    (sleep 5;echo $user;sleep 1;echo $passwd;sleep 2;echo "cd /rptpath"sleep 2;echo "tar xvfz rpt_$filename.tar.gz &";sleep 5;echo "exit";sleep 2)| telnet $host                 #经典之处

    echo $cdecho "完成"在1处,可以这样更为动态地选择日期DBUSER=dbuser;DBPASS=dbpwd;sqlplus "${DBUSER}/${DBPASS}" << ! >/dev/nullset pagesize 0;set long 90000;set feedback off;spool /tmp/tmp.txt;select date from tablename where condition;spool off;exit;!grep -v "^SQL" /tmp/tmp.txt >/tmp/date.txtdate=`cat /tmp/date.txt|cut -c1-8`echo "下发日期"echo $date


    最新回复(0)