#Log function Log() { createTime=`date +"%Y-%m-%d %H:%M:%S"` echo"[${createTime}] $*" |tee -a ${logFile} 2>/dev/null }
#CheckDir function CheckDir() { if [ ! -d $1 ]; then mkdir_log=` mkdir -p -m 775 $1 ` if [ $? -ne 0 ]; then Log "[ERROR] [$1] create failed, dir not exist, please check..." exit 255 fi fi } CheckDir "${logPath}"
################### Main program ################### #check the parameter if [ $# -ne 6 -a $# -ne 7 ]; then Log "[ERROR] Please input the right parameter ..." Log "[ERROR] Eg:sh ora_spool_data.sh oraSid user passwd /app/file/userinfo.ctl /app/file/userinfo.del" exit 1 fi
#Check ctlFile if [ ! -f ${ctlFile} ];then Log "[ERROR] ${ctlFile} not exist, please check..." exit 2 fi
if [ "${dbcode}" != "X" ];then export NLS_LANG=${dbcode} fi
#Check datapath datapath=`dirname${dataFile}` if [ ! -d ${datapath} ];then Log "[ERROR] ${datapath} is not exists, please check...." exit 3 fi
Log "=============${ctlFile}=============" Log "[INFO]: Begin to spool data to ${dataFile} from ${tabName}" #Begin time beginTime=`date +"%Y-%m-%d %H:%M:%S"`
sqlplus -s ${dbUser}/${dbPass}@${dbSid}<<EOF>/dev/null set trimspool on set echo off set linesize 30240 set pagesize 0 set newpage 1 set heading off set term off set feedback off
Log "[INFO]: End to spool data to ${dataFile} from ${tabName}, ${hour}h${min}m${sec}s..." Log "[INFO]: dataFile:${dataFile}" Log "[INFO]: logFile :${logFile}"