目标

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

源代码

通用函数脚本program_log_new.sh
function 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 脚本执行日志通用模块的更多相关文章

  1. [转]shell脚本打印日志方法

    该文章转自:http://blog.csdn.net/wylfengyujiancheng/article/details/50019299 ----------------------------- ...

  2. windows下建立文件的换行符^M导致linux下的shell脚本执行错误的解决方式

    常常在windows下编辑的文件远程传送到linux下的时候每行末尾都会出现^M.这将导致shell脚本执行错误,主要是由于dos下的编辑器和linux下的编辑器对文件末行的回车符处理不一致导致. 主 ...

  3. 远程shell脚本执行工具类

    /** * 远程shell脚本执行工具类 */public class RemoteShellExecutorUtils { private static final Logger logger = ...

  4. shell脚本执行错误 $'\r':command not found

    shell脚本执行错误 $'\r':command not found Linux下有命令dos2unix 可以用一下命令测试 vi -b filename 我们只要输入dos2unix *.sh就可 ...

  5. 用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql

    1:创建shell脚本 touch sqoop_options.sh chmod 777 sqoop_options.sh 编辑文件  特地将执行map的个数设置为变量  测试 可以java代码传参数 ...

  6. 2.8 补充:shell脚本执行方法

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限.   方法一:切换到shell脚本 ...

  7. 如何把rc.local里执行的shell脚本的日志内容放到其他位置

    rc.local的日志内容默认是/var/log/boot.log /etc/rc.d/rc.local文件的文件头是#!/bin/sh ,我们把这修改成#!/bin/sh -x,这样系统启动后就会把 ...

  8. 用 shell 脚本做日志清洗

    问题的提出 公司有一个用户行为分析系统,可以记录用户在使用公司产品过程中的一系列操作轨迹,便于分析产品使用情况以便优化产品 UI 界面布局.这套系统有点类似于 Google Analyse(GA),所 ...

  9. linux下shell脚本执行jar文件

    最近在搞一个shell脚本启动jar文件个关闭jar文件的东东.搞得我都蛋疼了.今天晚上终于弄好了 话说,小弟的linux只是刚入门,经过各方查资料终于搞定了.话不多说,下面开始上小弟写的shell脚 ...

随机推荐

  1. shutdown computer in ad and ou

    1. powershell Shutdown-computer –computername (gc c:\temp\serverlist.txt) –force –throttlelimit 10 h ...

  2. hibernate的formula如何使用

    之前用过hibernate的formula记得很好用,但是这次用到想不起来怎么用了,结果去网上查结果发现大多都是无用信息. 最终搞定了,还是在这里记录一下,省的忘记. 我用formula的目的在于字典 ...

  3. python系统编码格式

    python在安装的时候默认的编码格式是ASCII,当程序中出现非ASCII编码时,python的处理常常会报这样的错UnicodeDecodeError,python没办法处理非ASCII编码的,此 ...

  4. POJ2103 Jackpot

    Description The Great Dodgers company has recently developed a brand-new playing machine. You put a ...

  5. win7 安装SQL Server 2005 开发版 图文教程

    转自win7 安装SQL Server 2005 开发版 图文教程 ----------------------------写在安装前------------------------------ 一. ...

  6. SourceTree + Bitbucket - 轻松云端作业

    如何新建bitbucket工程 常见流程: 1: 本地电脑 A:创建Xcode工程 2:Bitbucket网站 A:"创建"仓库 B:然后"从零开始",根据提示 ...

  7. Android——service重启

    一.在application中注册消息监听 public class BackgroundServiceApplication extends Application { @Override publ ...

  8. Flash正则例子

    var jack:String = "zhuhai"; var arr:Array = ["23", "4", "67" ...

  9. (转载)c库不正确问题

    (转载)http://blog.csdn.net/piratejk/article/details/6115748 在linux下面变成,有时候在一个发行版本上编译通过,并且可以运行,但是将程序拷贝到 ...

  10. EF框架搭建

    EF框架搭配lambda表达式使用起来非常高效便捷,有两种方法使用EF框架: 一是.添加“ADO.NET Entity Data Model”项,绑定配置数据库链接,勾选表和存储过程等,自动生成实体: ...