Chinaunix首页 | 论坛 | 博客
  • 博客访问: 134827
  • 博文数量: 47
  • 博客积分: 1220
  • 博客等级: 中尉
  • 技术积分: 565
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-09 10:07
个人简介

unix/linux shell、c/c++、java、oracle pl/sql、db2 sql pl、informatica

文章分类

全部博文(47)

文章存档

2012年(11)

2011年(3)

2010年(8)

2009年(20)

2008年(5)

我的朋友

分类: 系统运维

2012-03-24 22:00:50

问题的提出
 
所用系统udm是c/c++程序,运行时会根据所运行的task_id 写日志,每月月帐期1至3号运行,由分部(广东21个地市)根据进度调度相应模块,udm系统运行在5台不同的Unix服务器上(hp/aix/sunos),而这些因为管理的需要都未对分部开放,于是问题就来了:分部如何知道自已调的程序是否有正常跑完?如何知道程序运行的进度?
 
问题的解决
 
两个月前写的,被实践证明确实有效
 
1、  21个地市建日志表

  1. create table UDM_ERROR_LOG
  2. (
  3.   sum_month VARCHAR2(12),
  4.   task_id VARCHAR2(25),
  5.   err_time DATE,
  6.   err_infor VARCHAR2(4000),
  7.   load_date DATE
  8. )
 
2、  5台服务器上部署脚本 chkudm.sh
 
#!/bin/sh
write_db()
{
        in_city=$1
        in_month=$2
        db_pwd=`cat $POCO_BASE/script/config/summary_ods_xx_pwd.config|grep ${in_city}|awk -F"" '{print $3}'`
        db_user=`cat $POCO_BASE/script/config/summary_ods_xx_pwd.config|grep ${in_city}|awk -F"" '{print $2}'`
        db_tns=`cat $POCO_BASE/script/config/summary_ods_xx_pwd.config|grep ${in_city}|awk -F"" '{print $4}'`
        orapwd="}"
       
        exesql=${HOME}/bin/fangp/chkudm/sql/delete.sql
       
        echo "set pagesize 0 feedback off verify off heading off echo off" >>${exesql}
        echo "begin" >>${exesql}
        echo "  EXECUTE IMMEDIATE 'delete from udm_error_log where trim(sum_month)=''${in_month}''';" >>${exesql}
        echo "  commit;" >>${exesql}
        echo "end;" >>${exesql}
        echo "/" >>${exesql}
        #echo ${orapwd}
        #cat ${exesql}
       
        `sqlplus -S $orapwd<               @${exesql}
               exit
         EOF
               exit`
       
        rm ${exesql}
       
        sqlldr userid=${orapwd} control=${HOME}/bin/fangp/chkudm/ctl/chk_file_${in_city}.ctl  log=${HOME}/bin/fangp/chkudm/log/chk_file_${in_city}.ctl.log
}

chk_log()
{
        in_city=$1
        in_month=$2
        sum_month=$3
        load_date=`date '+%Y-%m-%d %H:%M:%S'`
       
        #log path
        LOG_PATH=${HOME}/log
        cd $LOG_PATH
       
        chk_file=${HOME}/bin/fangp/chkudm/file/chk_file_${in_city}.txt
       
        tail -1 ServInfoManage_${in_city}.log|grep ${in_month}|awk -F'[][]' '{print "'"${sum_month}"'"  "|"  "ServInfoManage"  "|"  $2  "|"  $9  "|"  "'"${load_date}"'"}' >>${chk_file}
       
        #tail task_id  hff 200--29600, yffgw 28100--28500, yffcnet 21200--21600, arrear 26000、26100, gongyun 24000、 24100, hffpay 23100、23002
       
        for task_id in `echo 200 29000 29100 29300 29500 29200 29400 29600 28100 28200 28800 28900 28300 28400 28500 21200 21300 21400 21500 21600 26000 26100 24000 24100 23100 23002`
        do
                tail -1 ${in_city}.${task_id}.log|grep ${in_month}|awk -F'[][]' '{print "'"${sum_month}"'"  "|"  '"${task_id}"'  "|"  $2  "|"  $7  "|"  "'"${load_date}"'"}' >>${chk_file}
        done
       
       
        cat ServInfoManage_${in_city}.log|egrep 'ERROR|ORA'|grep ${in_month}|awk -F'[][]' '{print "'"${sum_month}"'"  "|"  "ServInfoManage"  "|"  $2  "|"  $9  "|"  "'"${load_date}"'"}'
       
        #ora / err
       
        for task_id in `echo 200 29000 29100 29300 29500 29200 29400 29600 28100 28200 28800 28900 28300 28400 28500 21200 21300 21400 21500 21600 26000 26100 24000 24100 23100 23002`
        do
                cat ${in_city}.${task_id}.log|egrep 'ERROR|ORA'|grep ${in_month}|awk -F'[][]' '{print '"${sum_month}"'  "|"  '"$task_id"'  "|"  $2  "|"  $7  "|"  "'"${load_date}"'"}' >>${chk_file}
        done   
   
}
 
if [ $# = 1 ]                                
then                                          
        in_date=$1
        year=`echo ${in_date}|cut -c 1-4`
        month=`echo ${in_date}|cut -c 5-6`
        CURR_MONTH=`echo ${year}-${month}`
        smonth=`echo ${in_date}|cut -c 1-6`                                  
else                                          
        CURR_MONTH=`date +'%Y-%m'`
        smonth=`date +'%Y%m'`              
fi 
rm ${HOME}/bin/fangp/chkudm/file/chk_file_??.txt
for city in `echo gz dg jm yj`
do
      chk_log ${city} ${CURR_MONTH} ${smonth}
      write_db ${city} ${smonth}
done


注:(1)每台机器,不同处是 for city in `echo gz dg jm yj` ,只要把相应地市名改下即可
       (2)awk -F""   ,引号处的分隔符是ctrl+s,用vi打开可以看到,用cat打开是看不出来的
 
 
3、入库的ctl文件
 

  1. append into table udm_error_log
  2. fields terminated by '|'
  3. (
  4.     sum_month,
  5.     task_id,
  6.     err_time date "yyyy-mm-dd hh24:mi:ss",
  7.     err_infor,
  8.     load_date date "yyyy-mm-dd hh24:mi:ss"
  9. )

 
 
4、  crontab 自动调度
 
0,5,10,15,20,25,30,35,40,45,50,55 * 1-3 * * (. /file3/app/.profile;/file3/app/bin/fangp/chkudm/chkudm.sh >>  /file3/app/bin/fangp/chkudm/log/chkudm.log 2>&1)
 
注:由于hp/aix/sunos 都不支持 */5  ,所以只能用上面的办法
 
***** command to be executed
-----
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59) 
阅读(1625) | 评论(2) | 转发(1) |
给主人留下些什么吧!~~

桔子T恤2012-03-27 22:32:16

好多代码……

夏冰软件2012-03-26 15:29:00

博主写的不错,支持一下