使用shell解析脚本依赖关系,并自动补数
将脚本依赖关系放到表中
使用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解析脚本依赖关系,并自动补数的更多相关文章
- Prism 4 文档 ---第3章 管理组件间的依赖关系
基于Prism类库的应用程序可能是由多个松耦合的类型和服务组成的复杂应用程序,他们需要根据用户的动作发出内容和接收通知进行互动,由于他们是松耦合的,他们需要一种方式来互动和交流来传递业务功能的需求. ...
- Makefile 7——自动生成依赖关系 三颗星
后面会介绍gcc获得源文件依赖的方法,gcc这个功能就是为make而存在的.我们采用gcc的-MM选项结合sed命令.使用sed进行替换的目的是为了在目标名前加上“objs/”前缀.gcc的-E选项, ...
- makefile自动生成依赖关系
手工编写依赖关系不仅工作量大而且极易出现遗漏,更新也很难及时,修改源或头文件后makefile可能忘记修改.为了解决这个问题,可以用gcc的-M选项自动生成目标文件和源文件的依赖关系.-M选项会把包含 ...
- Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本
Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本 在 mac 或者 linux 系统中,我们的浏览器或者其他下载软件下载的文件全部都下载再 ~/Downloads/ 文 ...
- pip自动生成requirements.txt依赖关系清单
Python项目中经常会带requirements.txt文件,里面是项目所依赖的包的列表,也就是依赖关系清单,这个清单也可以使用pip命令自动生成. pip命令: 1 pip freeze > ...
- 自动配置pom文件,构建maven项目jar包依赖关系,找到jar包运用到jmeter
首先说下pom文件特别方便的优点: 什么是pom文件? POM(Project Object Model) 是Maven的基础. 它是一个XML文件,包含了Maven用来build项目所需要的项目配置 ...
- Shell脚本交互之:自动输入密码
Shell脚本交互之:自动输入密码 2016年04月09日 19:41:26 zhangjikuan 阅读数:58208 标签: Shell交互自动输入密码expect重定向管道 更多 个人分类: A ...
- IDEA maven项目查自动查看依赖关系,解决包冲突问题
在maven项目中找到pom.xml,打开. <dependencies> <dependency> <groupId>org.apache.storm</g ...
- Ambari服务依赖关系图生成脚本
1. 生成服务依赖关系 #!/usr/bin/python import sys import commands import json def genDependString(ip): url=&q ...
随机推荐
- Matlab中的rectangle函数
rectangle函数功能:创建二维矩形对象. rectangle('Position',[x,y,w,h])从点(x,y)开始绘制一个宽w高h的矩形,对坐标轴数据单元指定值.注意,按指定的比例显示矩 ...
- Python学习之路基础篇--11-12Python基础,函数的装饰器
对于装饰器来说,就是在不改变函数的调用的情况下,对函数的前后增加了些许功能,这完全符合函数的 开放封闭 原则.装饰器的本质 其实就是一个闭包函数. 这是一个装饰器的步骤图 ret = func(*ar ...
- vm12pro 安装winxp过程 记录1(涵个人问题)
1.百度的xp资源 选好iso文件后出现如下情景: 2.百度以后是要在一开始的首次界面就选择从哪个盘开始 3.选择了“Windowgs PE”选项…加载出界面后选择了ghost xp…现在…黑屏了…… ...
- linux 在后台常驻运行php脚本
php a.php &
- Servlet中的编码问题
对于response.setContentType()和response.setCharacterEncoding()的理解: 经过一些实践,对着两个方法有了一些自己的理解,有可能今后的学习中会发现自 ...
- Ubuntu使用总结二
Ubuntu使用 - 1.ubuntu怎么切换到root用户,切换到root账号方法 ubuntu怎么切换到root用户,我们都知道使用su root命令,去切换到root权限,此时会提示输入密码, ...
- OSI七层网络模型浅析
OSI七层网络模型(从下往上): 物理层(Physical):设备之间的数据通信提供传输媒体及互连设备,为数据传输提供可靠的 环境.可以理解为网络传输的物理媒体部分,比如网卡,网线,集线器,中继器,调 ...
- [IOS][已越狱]配合网易云音乐,使用Bridge快速免iTunes导入音乐到“音乐”
前置:已越狱IOS设备 工具表: Bridge{bigboss源,可以使用cydown以非官方服务器下载安装} 网易云音乐{Appstore} Filza{很多源都有} 网易云试听缓存路径 ...
- 多线程之BlockingQueue中 take、offer、put、add的一些比较
一.概述: BlockingQueue作为线程容器,可以为线程同步提供有力的保障. 二.BlockingQueue定义的常用方法 1.BlockingQueue定义的常用方法如下: 抛出异常 ...
- asp.net core webapi处理Post请求中的request payload
request payload的Content-Type实际上是text/plain的,如果请求的 Content-Type 为 application/json,这将导致415 Unsupporte ...