Target
Implement recording of shell execution start time, end time, running status, error information, etc. Use the function to encapsulate log records and use scripts to call functions.
Source code universal function script 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 // public script init_log sh_xx // initialize the log function call and input the program name shell command XXX 2 >$ {logdir}/XX _ $ time. log exception_write // exception occurred. The call is abnormal. The program exits the shell command XXX 2 >$ {logdir}/XX _ $ time. log exception_write // exception occurred. The call is abnormal and the program exits .... shell Command XXX 2 >$ {logdir}/XX _ $ time. log finish_write // exception occurred. The call is abnormal and the program exits.