標籤:style io ar cti div 時間 line log
目標
實現記錄SHELL執行的開始時間,結束時間,運行狀態,錯誤資訊等,以函數封裝日誌記錄的方式,指令碼調用函數
源碼通用函數指令碼program_log_new.sh
function init_log(){sqlplus -S test/[email protected] <<EOFinsert into program_log values($id,$day,'$1', sysdate,null,'S',null);commitexitEOF}function modify_status(){sqlplus -S test/[email protected] <<EOFupdate program_log set program_status='$1',end_date=sysdate where id=$id;commitexitEOF}function exception_write(){if [ $? -ne 0 ]then modify_status $status2exit 1fi}function finish_write(){if [ $? -eq 0 ]then modify_status $status1#modify_status $1 $2 $3 else# modify_status $1 $2 $3 modify_status $status2exit 1fi}status1=Cstatus2=Fday=`date "+%Y%m%d"`id=`sqlplus -S user/[email protected] <<EOFset heading offselect program_log_seq.nextval from dual;commitexitEOF`
#!/bin/sh. ~/.bash_profilesource program_log_new.sh //通用指令碼init_log sh_xx //初始化日誌函數調用,傳入程式名shell命令xxx 2>${logdir}/xx_$time.log exception_write //發生異常,調用異常,程式退出shell命令xxx 2>${logdir}/xx_$time.log exception_write //發生異常,調用異常,程式退出....shell命令xxx 2>${logdir}/xx_$time.log finish_write //發生異常,調用異常,程式退出