kettle⽂件⾃动化部署(shell脚本执⾏):命令⾏参数传⼊
shell脚本中调⽤kitchen 和 pan去执⾏,job和transformation⽂件。分 windows和 dos系统两种。
举个简单的⼩例⼦
shell脚本:
export JAVA_HOME=/usr/local/java/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/mysql-connector-java-5.1.18-
bin.jar
export KETTLE_HOME=/home/www/allyes/a3tracker/bi/etl/kettle/kh_cloud/
export LC_ALL=en_US.UTF-8
echo "KETTLE_HOME=$KETTLE_HOME"
echo ""
yesterdayid=`date -d $yesterday +%Y%m%d`
/home/www/allyes/a3tracker/bi/etl/kettle/data-integration/kitchen.sh -param:Yesterday='2014-02-24' -file
/home/www/allyes/a3tracker/bi/etl/kettle/etlscript/playdata_etl_day.kjb>/home/www/allyes/a3tracker/bi/etl/kettle/logs/a3tracker
完整的脚本
#!/bin/sh
check_date()
{
[ $# -ne 1 ] && return 1
_lenStr=`expr length "$1"`
[ "$_lenStr" -ne 10 ] && return 1
date -d $1 "+%Y/%m/%d" | grep -q $1
if [ $? -eq 1 ]
then
return 1
else
return 0
fi
return 0
}
vardate=`date +%Y%m%d%H%M%S`
echo today is `date +%Y/%m/%d`
yesterday=`date -d "yesterday" +%Y/%m/%d`
shell最简单脚本while [ -n "$1" ]; do
case $1 in
-d)
shift
yesterday=$1
echo "your input is $yesterday"
shift;;
*)
echo "$1 is wrong paratism"
break;;
esac
done
check_date $yesterday
if [ $? -eq 1 ];then
echo "date format error! date format:(<yyyy/mm/dd>)"
exit 1
fi
echo Data aggregation date : $yesterday
export JAVA_HOME=/usr/local/java/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/mysql-connector-java-5.1.18-
bin.jar
export KETTLE_HOME=/home/www/allyes/a3tracker/bi/etl/kettle/kh_cloud/
export LC_ALL=en_US.UTF-8
echo "KETTLE_HOME=$KETTLE_HOME"
echo ""
yesterdayid=`date -d $yesterday +%Y%m%d`
/home/www/allyes/a3tracker/bi/etl/kettle/data-integration/kitchen.sh -param:Yesterday=$yesterday -file
/home/www/allyes/a3tracker/bi/etl/kettle/etlscript/playdata_etl_day.kjb>/home/www/allyes/a3tracker/bi/etl/kettle/logs/a3tracker echo "done!"
命令⾏参数传⼊:
⼏篇讲解:
两个例⼦,传⼊多个参数:
/home/www/allyes/aso/kettle/kitchen.sh -file /home/www/allyes/aso/etl/test.kjb -param:os='1' -param:appstore='all' -
param:dt='2014-02-24' >/home/www/allyes/aso/ 2>/home/www/allyes/aso/
/home/www/allyes/aso/kettle/kitchen.sh -file /home/www/allyes/aso/etl/test.kjb -param:os=1 -param:appstore='all' -
param:dt='2014-02-24' -level=Detailed >/home/www/allyes/aso/
命令⾏执⾏,options 后⾯可以是"="也可以是":"也可以是空格,三者都⾏,如kitchen.bat /file d:\ 或者 -file=D:\ 或者/file:D:\ kitchen.bat /norep -file=D:/kettledata/mysal2orcle.kjb >> kitchen_%date:~0,10%.log
两种格式(住linux下可以没有双引号quotation,windows要求参数parameter必须有双引号)
1:kitchen /file:"MyJob.kjb" /param:ServerName=MyServer
多个param:
Linux: ./kitchen.sh -file:job.kjb -param:files.dir=/opt/files -param:max.date=2010-06-02
Windows: Kitchen.bat -file:job.kjb “-param:files.dir=/opt/files” “-param:max.date=2010-06-02″
2:kitchen /file:"your job name.kjb" "command line argument 1" "command line argument 2" "command line argument 3"....
listparam,也是使⽤多个parameters,如:
sh pan.sh -file:/tmp/foo.ktr -listparam
Parameter: MASTER_HOST=, default=localhost : The master slave server hostname to connect to
Parameter: MASTER_PORT=, default=8080 : The master slave server HTTP control port
也可以写成,等同于:
sh pan.sh -file:/tmp/foo.ktr -param:MASTER_HOST=192.168.1.3 -param:MASTER_PORT=8181
Windows requires you to use quotes around the parameter otherwise the equals sign is treated as a space by the command interpreter:
c:\> pan.sh -file:/tmp/foo.ktr "-param:MASTER_HOST=192.168.1.3" "-param:MASTER_PORT=8181"
⽇志的选择,不同参数的设定:
-level ⽇志级别:(运⾏界⾯,log显⽰框左上⾓三个⼩图标,最后⼀个扳⼿锤⼦为设置level)
Rowlevel: print所有在Kettle中的有效⽇志,包括在⼤量复杂步骤的信息;
Debugging: 产⽣⼤量的⽇志信息,主要⽤于调试,但是不是在⾏级别(row level);
Detailed:允许⽤户看到⽐基本⽇志级别更富⽐较性的信息,额外的信息实例包括SQL查询语句和⼀般的DDL都会产⽣。
Basic:默认的⽇⼦级别;仅仅打印这些能够反映在步骤或者任务条⽬上的信息。
Minimal:通知你仅仅关于⼀个任务或者转化的信息。
Errorlogging only: 如果那⼉有⼀个错误,显⽰错误消息;否则,什么都不显⽰。
Nothingat all: 即使当有错误存在的时候,不要产⽣任何⽇志。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论