`
daohao123
  • 浏览: 56175 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

SHELL RECORD EXAMPLE

 
阅读更多
configFile=../../parm/output.config
runFolder=`cat ${configFile}|grep runFolder |awk -F= '{print $2}'`
outputFolder=`cat ${configFile}|grep outputFolder |awk -F= '{print $2}'`
outputFile=${outputFolder}/tolvdl_w_new_.txt
logName=$1
logName=${logName##*/}
logName=${logName%%.*}
logName="${logName}.log"
log=${runFolder}/output_FOLDER/${logName}
table=TABLENAME
fileSign=VDL
DB_SERV=`cat ${configFile}|grep DB_SERV |awk -F= '{print $2}'`
sql_source=`cat ${configFile}|grep sql_OSL |awk -F= '{print $2}'`
sql_result=`cat ${configFile}|grep sql_OIL |awk -F= '{print $2}'`

##replace the deffirent table and file name
sh tableReplace.sh $sql_source $sql_result ${fileSign} ${table}

#zip temp parameter
outputZip=${outputFolder}/zip/
zipPre=VDL_PRE
zipSuf=.zip
#zipAppend=(a b c d e f g h i j)
zipAppend=($(echo {a..z}))
tempNum=0
pageNum=`cat ${configFile}|grep pageNum |awk -F= '{print $2}'`

#read the email config
echo `date` "-------read the output.config file ------" >$log

failStr=`cat ${configFile}|grep fail |awk -F= '{print $2}'`
successStr=`cat ${configFile}|grep success |awk -F= '{print $2}'`
operatorName=`cat ${configFile}|grep operator |awk -F= '{print $2}'`
emailTitle=`cat ${configFile}|grep title |awk -F= '{print $2}'`


echo `date` "-------start to connect the DB and ouput the file ------" >>$log

#
#sqlplus to spool export the file
#
sqlplus -s /@${DB_SERV}<<EOF  >>$log 2>&1
WHENEVER SQLERROR exit failure rollback
set echo off
set feedback off
set termout off
set trimspool off
set linesize 1078
set pagesize 0
set heading off
spool $outputFile
@${sql_result}
spool off
EOF

if [ $? -eq 0 ]; then
   echo `date` ${successStr} >>$log
else
   echo `date` ${failStr} $log>>$log
   exit 1
fi

if [ -s $sql_result ]; then
rm $sql_result
fi


#make the file header and foot
lineLen=`cat ${configFile}|grep lineLen |awk -F= '{print $2}'`
dateStr=$(date +%m%d%y)
header=${dateStr}${fileSign}
while [ ${#header} -lt ${lineLen}  ]
do
header=${header}0
done

lastLine=$(tail -1 ${outputFile})
rowNum=${lastLine:1:9}

#check the rownum is 0?----
if [ $rowNum = "000000000" ] ; then
    tableEmpty=`cat ${configFile}|grep tableEmpty |awk -F= '{print $2}'`
    echo `date` ${tableEmpty}---${table}>>$log
    rm ${outputFile}
    #java com.javamail
    exit 1
fi

lastFileNum=`expr $rowNum % $pageNum `
#delete the last row
:|dd of=$outputFile seek=1 bs=$(($(find $outputFile -printf "%s")-$(tail -1 $outputFile|wc -c)))

#split the outputFile 2 million per file

echo `date` "-------start to split the file to ${pageNum}  per file ------" >>$log

if [ -s $outputFile ]; then
  mkdir ${outputZip} >>$log 2>&1
split -l ${pageNum}  $outputFile ${outputZip}temp_ >>$log 2>&1
echo `date` "-------end to split the file to ${pageNum}  per file ------" >>$log

#add the file header and footer
folderLen=$(ls -l ${outputZip}|grep "^-"|wc -l)
folderLen=`expr $folderLen - 1 `
for file_a in ${outputZip}/*; do 
   sed -i "1i${header}" $file_a
   tempfoot=""
if [ $folderLen -eq  $tempNum ] ; then
     while [ ${#lastFileNum} -lt 9  ]
         do
            lastFileNum=0${lastFileNum}
         done
         tempfoot="V${lastFileNum}"
     else
         while [ ${#pageNum} -lt 9  ]
         do
            pageNum=0${pageNum}
         done
         tempfoot="V${pageNum}"
         
     fi
     while [ ${#tempfoot} -lt ${lineLen}  ]
     do
       tempfoot=${tempfoot}0
     done
     echo $tempfoot >>$file_a   
     let tempNum++

done
tempNum=0
##END ADD HEADER AND FOOT
  #gzip the file

   for file_a in ${outputZip}/*; do 
    echo `date` "-------start to zip  ------${outputFolder}/${zipPre}${zipAppend[$tempNum]}${zipSuf} from  ${file_a} ">>$log
    fileTarget=${outputZip}/${zipPre}${zipAppend[$tempNum]}.txt
    mv ${file_a} ${fileTarget}
    zip -qm  ${outputFolder}/${zipPre}${zipAppend[$tempNum]}${zipSuf} ${fileTarget} >>$log 2>&1
    echo `date` "-------End to zip  ------${outputFolder}/${zipPre}${zipAppend[$tempNum]}${zipSuf} from   ${fileTarget} ">>$log
    let tempNum++

   done
   
  rm -rf ${outputZip}
  rm -f $outputFile
  echo `date` "-------remove the file-----${outputZip} and --${outputFile}">>$log
fi
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    android evi工具,按键录制、重放

    1 输入 adb shell evi record 后,做自己想要重复执行的操作。 2 输入 adb shell evi replay -t n ,即可重复执行操作,n代表想要重复执行的次数。 adb shell evi Usage: evi record [-f ] [] - record system ...

    Awk入门教程 《Awk A Tutorial and Introduction - by Bruce Barnett》

    Which shell to use with AWK? Dynamic Variables The Essential Syntax of AWK Arithmetic Expressions Unary arithmetic operators The Autoincrement and Autodecrement Operators Assignment Operators ...

    docker-changeip-updater:Docker 容器对 No-IP 帐户运行 DNS 更新

    export CHANGEIP_RECORD=myrecord.example.com 然后拉取最新的镜像并运行一次性容器来执行脚本: docker pull tribou/changeip-updater docker run --rm -it \ -e 'CHANGEIP_USERNAME' \ -e 'CHANGEIP_PASSWORD...

    最全的oracle常用命令大全.txt

    ORACLE常用命令 一、ORACLE的启动和关闭 1、在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su - oracle a、启动ORACLE系统 oracle&gt;svrmgrl SVRMGR&gt;connect internal ...

    python3.6.5参考手册 chm

    Python参考手册,官方正式版参考手册,chm版。以下摘取部分内容:Navigation index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python ...

    google repo工具

    # To create a new change record, leave the brackets empty. After the upload is complete the changes will have an additional Patch Set. If you only want to upload the currently checked out Git branch...

    VB编程资源大全(英文源码 控件)

    &lt;END&gt; 48,ShellLnk.zip ShellLink ActiveX Control 1.0 can retrives and save all the information from a shortcut file(.lnk extension) which can be accessed by using various properties and methods...

    VB编程资源大全(英文源码 其它)

    cube.zip This example demonstrates how to rotate a cube in visual basic.&lt;END&gt;&lt;br&gt;17 , sprite1.zip This is an Excellent example on how to use sprites in your program.&lt;END&gt;&lt;br&gt;18 , charcreate.zip...

    Python for Bioinformatics 第二版,最新版

    2.2.5 Exit from the Python Shell 27 2.3 BATCH MODE 27 2.3.1 Comments 29 2.3.2 Indentation 30 2.4 CHOOSING AN EDITOR 32 2.4.1 Sublime Text 32 2.4.2 Atom 33 2.4.3 PyCharm 34 2.4.4 Spyder IDE 35 2.4.5 ...

    Beginning Python (2005).pdf

    Try It Out: Very Simple Record Retrieval 436 Try It Out: Very Simple Record Storage 438 Try It Out: Data Storage in MySQL 439 Try It Out: Storing and Retrieving Documents 441 Try It Out: A ...

    EurekaLog_7.5.0.0_Enterprise

    10)..Fixed: Ignore timeouts from Shell_NotifyIcon 11)..Fixed: Possible failure to handle/process stack overflow exceptions 12)..Changed: VCL/CLX/FMX now will assign Application.OnException handler ...

    (重要)AIX command 使用总结.txt

    Record: 252; Size 344064. ---磁带机文件头大小 tcopy: File: 1; End of File after: 252 Records, 526729216 Bytes. ---文件大小 tcopy: The end of the tape is reached. tcopy: The total tape length is ...

    UE(官方下载)

    Steps to record and edit powerful macros to quickly and efficiently edit files Using "copied" and "selected" variables for dynamic macros Use copied and selected text in macros to dramatically ...

    Debugging with GDB --2007年

    2.3 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5 6 6 6 6 6 7 7 7 8 11 11 13 15 15 16 GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . ...

Global site tag (gtag.js) - Google Analytics