public.sh

#脚本公共函数库

MachineType=`uname`

#当天日期
DATE=`date '+%Y%m%d'`

#当年年号
YEAR=`date '+%Y'`

#当月月号
MONTH=`date '+%m'`

#当天天号
DAY=`date '+%d'`

ManRptDir=~report/management

SrvRptDir=~report/service

KpiRptDir=~report/kpi

TmpDir=$HOME/smp_run/smpser/temp

LogDir=$HOME/smp_run/smpser/log

ExceptDir=$HOME/smp_run/smpser/exception/report

SmpserDir=$HOME/smp_run/smpser

#********************************1.LOG FUNCTION**************************************

#以下三个Log函数是报表程序都需要的,其中:
#    Log()函数用于在报表程序执行期间向屏幕和LogFile内写日志
#    LogStart()函数用于写报表头。
#    LogEnd()函数用于写报表尾。
#在调用这些函数前,需要定义的变量为LogFile,用于指明日志文件的
#路径和文件名。例如:
#    LogFile=$HOME/smp_run/runlog/smp_report.log

Log()
{
    timestr=`date '+%Y-%m-%d %H:%M:%S '`

    if [ "-$LogFile" = "-" ]; then
        echo "ERROR: LogFile is not defined!"       
        exit 1
    fi
    #如果带-s参数,说明既向日志文件输出,同时也需要向屏幕输出
    if [ "x$1" = "x-s" ]; then
        shift
        echo "$*" >> $LogFile
        echo "$*"
    else
    #否则,只向日志文件输出
        echo ${timestr}"$*" >> $LogFile
        echo ${timestr}"$*"
    fi
}

#调用格式:LogStart 程序名
#例如:LogStart $0
LogStart()
{
    Log -s " "
    Log -s " "
    Log "++++++++++  $1 Start  ++++++++++"
}

#调用格式:LogEnd 程序名
#例如:LogEnd $0
LogEnd()
{
    Log "----------  $1  End   ----------"
    Log -s " "
}

#PPSV800R004C04B30 added by zhangzhifa60015597 2007-02-15 begin
##=============================================================
#函数名称:LogDebug
#函数描述:调试信息
#          1.需要设置调试开关 LogDebugSwitch=1 or LogDebugSwitch=0;
#                             1--表示打开调试开关,0--表示关闭调试开关
#输入参数:无
#返回值:         
#       0  成功
#       1  失败
#调用方式:LogDebug "信息内容"
##=============================================================
LogDebug()
{
    if [ "-$LogDebugSwitch" != "-1" ]; then
        return 0
    fi
    Log "[DEBUG] $*"
    return 0
}
##=============================================================
#函数名称:LogBreak
#函数描述:调试用中断
#           1.需要设置调试开关  LogDebugSwitch=1 or LogDebugSwitch=0;
#                               1--表示打开调试开关,0--表示关闭调试开关
#           2.需要设置中断开关  LogBreakSwitch=1 or LogBreakSwitch=0;
#                                1--表示打开中断开关,0--表示关闭中断开关
#输入参数:无
#返回值:         
#       0  成功
#       1  失败
#调用方式:LogBreak
##=============================================================

LogBreak()
{
    if [ "-$LogDebugSwitch" != "-1" ]; then
        return 0
    fi
   
    if [ "-$LogBreakSwitch" != "-1" ]; then
        return 0
    fi
   
    Log "Press n/N to exit, or else continue..."
    read LogBreakVal
   
    if [ "-$LogBreakVal" != "-n" -a "-$LogBreakVal" != "-N" ]; then
        return 0
    fi
   
    exit
}

#PPSV800R004C04B30 added by zhangzhifa60015597 2007-02-15 end


#Begin add by Zhang Yongfeng 20051226
##############################################################################
#函数名称:CheckLogEnv
#函数描述:检查平台运行日志目录及程序日志文件的大小
#返回值:0--正确         
#        1--错误
CheckLogEnv()
{
    #平台日志目录检测
    if [ ! -d $LogDir ]; then
        echo "Error:the log file directory $LogDir is not exist"
        return 1
    fi
   
    #程序日志文件维护
    if [ -s ${LogFile} ]; then
        logsize=`ls -l ${LogFile} | awk '{printf "%s", $5}'`
        if [ ${logsize} -ge 3000000 ]; then
            mv ${LogFile} ${LogFile}.old
            touch ${LogFile}
        fi
    fi
   
    return 0
}
#End add by Zhang Yongfeng 20051226

##############################################################################
#函数名称:CheckRuntimEnv
#函数描述:检查平台运行环境:数据库名、报表运行临时目录等
#返回值:0--平台环境正确         
#        1--平台环境错误
CheckRuntimeEnv()
{
    # 检查环境变量
    if [ "-$SMPDBNAME" = "-" ]; then
        Log "Error:the parameter of SMPDBNAME is wrong"
        return 1
    fi

    if [ "-$SMS_RUN" = "-" ]; then
        Log "Error:the parameter of SMS_RUN is wrong"
        return 1
    fi
       
    if [ "-$SMS_DIR" = "-" ]; then
        Log "Error:the parameter of SMS_DIR is wrong"
        return 1
    fi

    # 检查临时目录
    if [ ! -d $TmpDir ]; then
        Log "Error:the temp directory for SMP-SER running named $TmpDir not exist"
        return 1
    fi
   
    # 检查数据目录
    if [ ! -d $DataDir ]; then
        Log "Error:the data directory for SMP-SER running named $DataDir not exist"
        return 1
    fi   

    # 检查异常数据目录
    if [ ! -d $ExceptDir ]; then
        Log "Error:the exception directory for SMP-SER running named $ExceptDir not exist"
        return 1
    fi   
 
    return 0
}

############################################################################
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值