Shell脚本以记录日志来触发过程

时间:2019-12-12 22:50:10

标签: shell

这是需要触发存储过程的shell脚本,当记录计数为0时,它应该在日志中捕获找到0个重复记录的记录,如果大于0,则不记录任何日志。 另外,如果存在任何sqlerror,则它应该在日志文件中写入sqlerror,并且应该在所有情况下发送通信。 我们有已经用所有目录声明的funct文件,我们在这里指的是日志文件路径目录。 您能帮我纠正代码逻辑吗?

    #!/bin/ksh
    . /local/dir1/funct.sh
    sqlplus -s ${ORAUSER}/${ORAPASSWD}@${ORASRVC} <<EOF > $LOG_TEXT 
    set head off
    set serveroutput on
    SELECT TO_CHAR(SYSDATE,'MMDDRRRRHH24MISS') FROM DUAL;
    EOF    
 TIME_STAMP=`cat ${LOG_TEXT}`    
 LOG_FILE_NAME='FileStatus'${TIME_STAMP}'.log'
 LOG_FILE=${LOGFILEDIR}'/FileStatus/'${LOG_FILE_NAME}

write_log "Database Timestamp is $TIME_STAMP"
write_log "Executing FileStatus now..."

sqlplus -s ${ORAUSER}/${ORAPASSWD}@${ORASRVC} <<EOF >> ${LOG_TEXT} 
set feedback off
set heading off
DECLARE
v_count NUMBER;
BEGIN
select count(*) INTO v_count from (select col1,col2,count(col3) from Tab1 group by col1,col2 having count(col3)>1);
whenever sqlerror exit -1
whenever oserror exit -1
execute FileStatus;
END;
EOF

if [[ v_count -eq 0 ]] then
        write_log "FileStatus executed successfully."
    write_log "No Duplicate records Found: $LOG_FILE"
         mailx -s "No Duplicate records Found" XXXXX@gmail.com < ${success}
elif [[ "$v_count -gt 0 ]] 
 then
        write_log "FileStatus  executed successfully."
    write_log "Number of duplicate records found::$v_count:$LOG_FILE"
        mailx -s "Number of duplicate records found:$v_count" XXXXX@gmail.com < ${success}
else
        Write_log "FileStatus Failure."
         mailx -s "FileStatus" XXXXX@gmail.com < ${failure}

fi  
cleanup
exit 0;

0 个答案:

没有答案