zoukankan      html  css  js  c++  java
  • 【shell实例】定时21:00-21:05,循环调用DSQL脚本,其它时段自动退出

    1.功能描述:

    每日21:00定时调起test.sh,循环调起DSQL脚本test.dsql,直到21:05程序自动退出,捕获日志到相应log文件中。

    2.日志文件:

    (1)日期.log文件中含Error Time即为错误;

    (2)日期目录中log文件为调用dsql详细日志;

    (3)test.log文件中为捕获的屏幕输出日志。

    3.程序部署:

    (1)ETL服务其中新建目录/tmp/zlt,将附件脚本上传至该目录

    mkdir -p /tmp/zlt

    (2)赋权

    cd /tmp/zlt
    chmod +x test.sh
    chmod +x test.dsql

    (3)定时启动

    crontab -e
    0 21 * * * /tmp/zlt/test.sh>>/tmp/zlt/test.log

    4.取消定时启动

    crontab -e
    删除新增内容即可

    5.test.sh代码

    #!/bin/sh
    dir_home="/tmp/zlt"
    curr_date=`date +%Y%m%d`
    log_dir=${dir_home}/${curr_date}
    result_log=${dir_home}/${curr_date}.log
    
    `mkdir -p ${log_dir}`
    
    
    be_s=2100
    en_s=2105
    curr_s=`date +%H%M`
    
    echo "[curr_dt]:$curr_date"
    echo "[log_dir]:$log_dir"
    echo "[rlt_log]:$result_log"
    echo "[curr_s]:$curr_s"
    echo "[be_s  ]:$be_s"
    echo "[en_s  ]:$en_s"
    
    if [ "$curr_s" -lt "$be_s" ] || [ "$curr_s" -gt "$en_s" ];then
        echo "curr_s is not between $be_s and $en_s"
      exit
    fi
    
    echo "">${result_log}
    count=1
    while [ "$be_s" -le "$en_s" ]
    do
     echo "========count:$count=========">>${result_log}
     echo "[Start Time]:"`date +%F.%H:%M:%S.%N`>>${result_log}
    Dsql -c $ETL_HOME/etc/logon_stg.env -f ${dir_home}/test.dsql 2>&1 >${log_dir}/test${count}.log
    if [ $? != 0 ];then
     echo "[Error Time]:"`date +%F.%H:%M:%S.%N`>>${result_log}
    fi
     echo "[End   Time]:"`date +%F.%H:%M:%S.%N`>>${result_log}
    
     count=$[$count+1]
     be_s=`date +%H%M`
        
    done

    6.test.dsql代码

    sel current_time
    .IF ERRORCODE <> 0 THEN .QUIT 12
    .QUIT 0
  • 相关阅读:
    empty() 为true
    浅谈Linux cp命令
    Centos7 出现Welcome to emergency mode!【紧急模式】
    Linux系统管理命令-systemctl 和 sshd 服务
    Linux 配置 history 命令显示操作时间、用户和登录 IP
    SHELL 中条件语句的运用 if for 条件测试语句
    CentOS 7 使用 HP 打印机
    Xmanager 5远程连接CentOS7图形化界面
    chmod命令用法详解-chmod修改目录权限
    centos crontab用法详解 定时任务的设置
  • 原文地址:https://www.cnblogs.com/badboy200800/p/10770152.html
Copyright © 2011-2022 走看看