将脚本依赖关系放到表中

使用shell解析脚本依赖关系,递归的计算各个脚本。

#!/bin/bash
# 2017.08. dm 补数 basepath=$(cd `dirname $`; pwd)
cd $basepath source /etc/profile
source ../etc/env.ini if [[ $# -ne ]]; then
echo "参数格式错误!"
echo "$0 [运算日期,格式:'yyyy-mm-dd'] [运算类型:down/up] [表名列表] "
echo "注:运算类型:down:表名是dm结果表,首先查找并调用其依赖的脚本,然后调用结果表。up:根据传入的前置表,查找其影响的结果表,然后执行。"
echo "注:表名列表 (如果传入一个以上的表,需要用\" \"分割,\"\"包裹):单表,例如“dm_event_meterial”;多表,例如“\dm_event_meterial,dm_voice_meterial\"”"
exit
fi #运算类型 run_type down up
run_type=$
#脚本名
shellNames=$
#运算日期
sdate=$(date -d "-1 day" "+%Y-%m-%d")
if [[ $# -eq ]]; then
sdate=$(date -d "$1" "+%Y-%m-%d")
fi #映射关系缓存
dmDic=""
#刷新映射关系缓存
function dic(){
local dm=$
dmDic=$(spark-sql -e "
use $HIVE_DB_ODS_S;
select concat_ws(\",\",tmp.dm,tmp.shell) from
(
select dm,shell
from yq_control_execute
where dm=\"$dm\"
union
select c2.dm as dm,c2.shell as shell
from yq_control_execute c1
inner join
yq_control_execute c2
on c1.shell = c2.dm
where c1.dm=\"$dm\"
union
select c3.dm as dm,c3.shell as shell
from yq_control_execute c1
inner join
yq_control_execute c2
on c1.shell = c2.dm
inner join
yq_control_execute c3
on c2.shell = c3.dm
where c1.dm=\"$dm\"
) tmp where tmp.shell!=tmp.dm
;
")
} #将参数的shell列表转化为dm列表
function getDms(){
local first=
shellNameSqlPart=""
for _shellName in $shellNames
do
if [[ "$first" -ne "" ]]; then
shellNameSqlPart=$shellNameSqlPart",\"$_shellName\""
else
shellNameSqlPart=\"$_shellName\"
((first++))
fi
done
echo $(spark-sql -S -e "
use $HIVE_DB_ODS_S;
select dm from
(
select dm
from yq_control_execute
where shell in ($shellNameSqlPart)
union
select c1.dm
from yq_control_execute c1
inner join
yq_control_execute c2
on c1.shell = c2.dm
where c2.shell in ($shellNameSqlPart)
union
select c1.dm
from yq_control_execute c1
inner join
yq_control_execute c2
on c1.shell = c2.dm
inner join
yq_control_execute c3
on c2.shell = c3.dm
where c3.shell in ($shellNameSqlPart)
) tmp
;
")
} #根据dm返回其依赖的shell列表
function getShellS() {
if [[ $# -ne ]]; then
echo "$0 parameter length error."
exit
fi
local target=$
local shells=""
for line in $dmDic
do
local __dm=$(echo $line|cut -d ',' -f )
local __shell=$(echo $line|cut -d ',' -f )
if [[ "$target" == "$__dm" ]]; then
local shells=$shells" "$__shell
fi
done
echo $shells
} runnedArray="" runCount= #检查并执行脚本
#只执行dm开头并且没有执行过的脚本,执行过后存入已执行列表
function checkAndRun(){
local flag=
local c_shell=$
for record in $runnedArray
do
if [[ "$record" == "$c_shell" ]]; then
local flag=
fi
done
# echo "已执行的脚本"$runnedArray
if [[ "$flag" == "" && "${c_shell:0:2}" == "dm" ]]; then
runnedArray="$runnedArray ${c_shell}"
((runCount++))
echo "【$runCount】sh ./deal/${c_shell}.sh"
sh ./deal/${c_shell}.sh $sdate
sh ./export/main.sh $sdate ${c_shell}
fi
} #递归执行dm
function run(){
local _dm=$
for shell in $(getShellS $_dm)
do
# echo $shell"==>"$_dm
if [[ "${shell:0:2}" == "dm" ]]; then
run $shell
checkAndRun $shell
fi
done
if [[ "${_dm:0:2}" == "dm" ]]; then
checkAndRun $_dm
fi
} if [[ "$run_type" == "up" ]]; then
#找出其对应的结果表 遍历执行
for dm in $(getDms $shellNames)
do
#执行前 更新依赖关系
dic $dm
run $dm
done
else
#遍历执行传入的dm列表
for dm in $shellNames
do
#执行前 更新依赖关系
dic $dm
run $dm
done
fi

脚本依赖表的格式:

这个依赖表除了有脚本的源表和目标表的关系,还有数据的来源类型(平台和渠道);如果要实现基本功能的话,如下几列即可。

 
类型 注释
from string 源表
to string 目标表

使用shell解析脚本依赖关系,并自动补数的更多相关文章

  1. Prism 4 文档 ---第3章 管理组件间的依赖关系

     基于Prism类库的应用程序可能是由多个松耦合的类型和服务组成的复杂应用程序,他们需要根据用户的动作发出内容和接收通知进行互动,由于他们是松耦合的,他们需要一种方式来互动和交流来传递业务功能的需求. ...

  2. Makefile 7——自动生成依赖关系 三颗星

    后面会介绍gcc获得源文件依赖的方法,gcc这个功能就是为make而存在的.我们采用gcc的-MM选项结合sed命令.使用sed进行替换的目的是为了在目标名前加上“objs/”前缀.gcc的-E选项, ...

  3. makefile自动生成依赖关系

    手工编写依赖关系不仅工作量大而且极易出现遗漏,更新也很难及时,修改源或头文件后makefile可能忘记修改.为了解决这个问题,可以用gcc的-M选项自动生成目标文件和源文件的依赖关系.-M选项会把包含 ...

  4. Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本

    Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本 在 mac 或者 linux 系统中,我们的浏览器或者其他下载软件下载的文件全部都下载再 ~/Downloads/ 文 ...

  5. pip自动生成requirements.txt依赖关系清单

    Python项目中经常会带requirements.txt文件,里面是项目所依赖的包的列表,也就是依赖关系清单,这个清单也可以使用pip命令自动生成. pip命令: 1 pip freeze > ...

  6. 自动配置pom文件,构建maven项目jar包依赖关系,找到jar包运用到jmeter

    首先说下pom文件特别方便的优点: 什么是pom文件? POM(Project Object Model) 是Maven的基础. 它是一个XML文件,包含了Maven用来build项目所需要的项目配置 ...

  7. Shell脚本交互之:自动输入密码

    Shell脚本交互之:自动输入密码 2016年04月09日 19:41:26 zhangjikuan 阅读数:58208 标签: Shell交互自动输入密码expect重定向管道 更多 个人分类: A ...

  8. IDEA maven项目查自动查看依赖关系,解决包冲突问题

    在maven项目中找到pom.xml,打开. <dependencies> <dependency> <groupId>org.apache.storm</g ...

  9. Ambari服务依赖关系图生成脚本

    1. 生成服务依赖关系 #!/usr/bin/python import sys import commands import json def genDependString(ip): url=&q ...

随机推荐

  1. swagger2常用注解

    常用注解: @Api()用于类: 表示标识这个类是swagger的资源 @ApiOperation()用于方法: 表示一个http请求的操作 @ApiParam()用于方法,参数,字段说明: 表示对参 ...

  2. centos7下部署node应用程序

    一.安装node 二.安装nginx 三.使用express写一个简单的demo,并且使用pm2部署 四.错误 invalid PID number "" in "/ru ...

  3. 安卓开发学习之Menu

    安卓开发中菜单是一个很重要的组件,从安卓开发文档(http://wear.techbrood.com/guide/index.html)中可以看到,安卓UI设计中的Menu主要分为: A.Option ...

  4. 本博客不再更新和维护,后续文章会在掘金和GitHub发布,感兴趣的小伙伴可以掘金搜索王振宇,谢谢

    本博客不再更新和维护,后续文章会在掘金和GitHub发布,感兴趣的小伙伴可以掘金搜索王振宇,谢谢

  5. 项目里如何访问AppDelegate

    项目里面访问AppDelegate做全局变量用有好几种方式 最原始就是 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication shared ...

  6. [Java Web学习]JSP中uri="http://java.sun.com/jsp/jstl/core"报红错误

    在官网下载jstl.jar和standard.jar,问题解决.

  7. miniui的联动列表

    function OnCellBeginEdit(e) { var grid = e.sender; var column = e.column; if (!column.parentfield) { ...

  8. 如何安装私有 npm 包?

    安装私有 npm 包的步骤: 先安装私有 npm 包:npm install <npm包名> --registry=<npm包源> 然后运行npm install安装公共 np ...

  9. Flutter Inspector 功能:Toggle Platform,Show Debug Paint,Show Paint Baselines

    Flutter Inspector 功能 说明 Toggle Platform 切换操作系统(Android.iOS) Show Debug Paint Show Paint Baselines Wi ...

  10. spring事务详解(三)源码详解

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...