Target
Implementation records the start time and end time of the shell execution. Execution state, error message, and so on, the script calls the function in the way that the function encapsulates the log record
Source CodeGeneral function Script program_log_new.sh
function init_log () {sqlplus-s test/[email protected] <<eofinsert into Program_log values ($id, $day, ' $ ', sysdate,null, ' S ', null); Commitexiteof}function modify_status () {sqlplus-s test/[ Email protected] <<eofupdate Program_log set program_status= ' $ ', end_date=sysdate where id= $id; Commitexiteof}function Exception_write () {if [$?-ne 0]then modify_status $status 2exit 1fi}function finish_write () {if [$ ? -eq 0]then modify_status $status 1#modify_status $ $ $ else# modify_status $2exit modify_status $status tus1=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 //Common script Init_log sh_xx //Initialize log function call, incoming program name shell command XXX 2> ${logdir}/xx_$time.log exception_write //exception occurred. Call exception, program exit shell command xxx 2>${logdir}/xx_$time.log exception_write //exception occurred. Call exception. Program quit .... shell command xxx 2>${logdir}/xx_$time.log finish_write //exception occurred, call exception, program exit
Shell script execution Log Generic module