shell 脚本执行日志通用模块
2016-04-02 18:44
459 查看
目标
实现记录SHELL执行的開始时间,结束时间。执行状态,错误信息等,以函数封装日志记录的方式,脚本调用函数源代码
通用函数脚本program_log_new.shfunction init_log() { sqlplus -S test/passw0rd@orcl <<EOF insert into program_log values($id,$day,'$1', sysdate,null,'S',null); commit exit EOF } function modify_status(){ sqlplus -S test/passw0rd@orcl <<EOF update program_log set program_status='$1',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`
#!/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 //发生异常,调用异常,程序退出
相关文章推荐
- Shell特殊变量: $0, $#, $*, $@, $?, $$, $!, $_和命令行参数$n
- Hbase shell <一>
- shell script
- bash shell的操作环境
- shell的变量功能
- shell脚本实现检測回文字符串
- linux shell常用快捷键 通配符
- Linux_Shell初级编程入门
- Shell脚本
- Linux C实现简单的shell
- shell、C中mysql插入数据语句
- Mac 下新建 .bash_profile 文件
- bash:command not found
- Linux Shell 学习笔记2:Shell变量
- 关于XShell远程登录显示乱码问题的解决方案
- I.MX6 Android Linux shell MMPF0100 i2c 获取数据
- .bash_profile
- 认识与学习bash
- 用代码定位硬盘上的文件(使用ShellExecute执行explorer /select命令,其它参数也很全)
- React Native (Mac) 终端修改 ~/.bashrc, ~/.profile, ~/.zshrc