我有以下shell脚本:
DATE= date +"%d%b%y" -d "-1 days"
如何将DATE
传递给Java操作?
答案 0 :(得分:8)
您可以捕获shell脚本的输出并将其传递给java action。在shell脚本中,回显属性,如'dateVariable = $ {DATE}',并在shell操作中添加capture-output元素。这将允许您从shell脚本捕获dateVariable。在java操作中,您可以将捕获的变量作为参数传递给 $ {wf:actionData('shellAction')['dateVariable']}其中shellAction是shell动作名称。
示例工作流程: -
<?xml version="1.0" encoding="UTF-8"?>
<workflow-app xmlns="uri:oozie:workflow:0.4"
name="Test workflow">
<start to="shellAction" />
<action name="shellAction">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<exec>test_script.sh</exec> <file>${nameNode}/${workFlowLocation}/Scripts/test_script.sh#test_script.sh</file>
<capture-output />
</shell>
<ok to="JavaAction" />
<error to="fail" />
</action>
<action name="JavaAction">
<java>
<main-class>com.test.TestDriver</main-class>
<arg>${wf:actionData('shellAction')['dateVariable']}</arg>
<capture-output />
</java>
<ok to="end" />
<error to="fail" />
</action>
<kill name="fail">
<message>Job failed, error
message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end" />
</workflow-app>
在shell脚本中,回显下面的值
echo "dateVariable=${dateValue}"