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