Rumah > pangkalan data > tutorial mysql > shell脚本运行日志通用模块

shell脚本运行日志通用模块

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-07 15:59:55
asal
1882 orang telah melayarinya

目标 实现记录SHELL执行的开始时间,结束时间,运行状态,错误信息等,以函数封装日志记录的方式,脚本调用函数 源码 通用函数脚本program_log_new.sh function init_log(){sqlplus -S test/passw0rd@orcl EOFinsert into program_log values($id,$day,$1, s

目标

实现记录SHELL执行的开始时间,结束时间,运行状态,错误信息等,以函数封装日志记录的方式,脚本调用函数

源码

通用函数脚本program_log_new.sh
function init_log()
{
sqlplus -S test/passw0rd@orcl <<EOF
insert into program_log values($id,$day,&#39;$1&#39;, sysdate,null,&#39;S&#39;,null);
commit
exit
EOF
}
function modify_status(){
sqlplus -S test/passw0rd@orcl <<EOF
update program_log set program_status=&#39;$1&#39;,end_date=sysdate where id=$id;
commit
exit
EOF
}


function exception_write(){
if [ $? -ne 0 ]
then
 modify_status $status2
exit 1
fi
}
function finish_write(){
if [ $? -eq 0 ]
then
 modify_status $status1
#modify_status $1 $2 $3
 else
#  modify_status $1 $2 $3
 modify_status $status2
exit 1
fi
}
status1=C
status2=F
day=`date "+%Y%m%d"`
id=`sqlplus -S user/1234@test <<EOF
set heading off
select  program_log_seq.nextval from dual;
commit
exit
EOF`
Salin selepas log masuk
#!/bin/sh
. ~/.bash_profile
source 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                                       //发生异常,调用异常,程序退出
Salin selepas log masuk
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan