Shell script execution Log Generic module

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.