Common shell script running Log Module

Source: Internet
Author: User
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.



Related Article

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.