目标

实现记录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. simhash--文本排重

    转载自 https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/06.12.md http: ...

  2. python 处理cookie简单很多啊 httpclient版本是4.3.3

    模拟登录流程: 1 请求host_url 2 从host_url中解析出 隐藏表单 的值 添加到POST_DATA中 3 添加账户,密码到POST_DATA中 4 编码后,发送POST请求    要点 ...

  3. BZOJ 1571: [Usaco2009 Open]滑雪课Ski

    Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S& ...

  4. uva 11922 - Permutation Transformer

    splay的题: 学习白书上和网上的代码敲的: #include <cstdio> #include <cstring> #include <cstdlib> #i ...

  5. HTML5 push

    http://blog.csdn.net/yo548720570/article/details/8599947 http://www.oschina.net/question/82993_63312 ...

  6. angular中实现jQuery的Document Ready

    angular中不推荐混用JQuery的,原因呢问度娘. 其实这是一个比较蛋疼的问题,尤其是angular2.0,尽量不要在页面上写js,用ts写到模块里面去吧.. 汲取各位先人的智慧,还是列一下 w ...

  7. 剖析Qt的事件机制原理

    版权声明 请尊重原创作品.转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正. QT源码解析(一) QT创建窗口程序.消息循环和WinMai ...

  8. 转载:浅谈Java多线程的同步问题【很好我就留下来,多分共享】

    转载:http://www.cnblogs.com/phinecos/archive/2010/03/13/1684877.html#undefined 多线程的同步依靠的是对象锁机制,synchro ...

  9. eMMC(KLM8G2FE3B)

     Tiny4412原理图中,eMMC是169-PIN,资料中对应内存为16/32G:而用户手册上eMMC内存为4G,对应的是153-PIN?    原理图中上标注:KLM8G2FE3B-B001_1. ...

  10. BlockingQueue-线程的阻塞队列

    BlockingQueue作为线程容器,可以为线程同步提供有力的保障,其主要用到的方法包括: add(E o); //将指定的元素添加到此队列中(如果立即可行),在成功时返回 true,其他情况则抛出 ...