我正在使用oozie
发送带附件的电子邮件。我在这样做。
<workflow-app name="Email" xmlns="uri:oozie:workflow:0.5">
<start to="email-0fdf"/>
<kill name="Kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="email-0fdf">
<email xmlns="uri:oozie:email-action:0.2">
<to>xxxxxxxxxxxxxxx@xxxxx</to>
<subject>job success</subject>
<content_type>text/plain</content_type>
<attachment>/user/XXXX/logs/2017-05-03/exec.log</attachment>
</email>
<ok to="End"/>
<error to="Kill"/>
</action>
<end name="End"/>
</workflow-app>
现在,在<attachment>/user/XXXX/logs/2017-05-03/exec.log</attachment>
附近的工作流程中,日期始终会发生变化。
如何传递调用工作流时的变量,然后我想发送该特定日期的附件。
编辑问题。
我的shell脚本:
#!/bin/bash
TIMESTAMP=`date "+%Y-%m-%d"`
path=/user/$USER/logging/${TIMESTAMP}/status/${TIMESTAMP}.fail_log
path1=/user/$USER/logging/`date -d "-1 days" '+%Y-%m-%d'`/status/`date -d "-1 days" '+%Y-%m-%d'`.fail_log
echo filePath=$path
echo filePath1=$path1
我的新工作流程:
<workflow-app name="My_Workflow" xmlns="uri:oozie:workflow:0.5">
<start to="shell-05e6"/>
<kill name="Kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="shell-05e6">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<exec>shell.sh</exec>
<file>/user/xxxxx/oozie/email/lib/shell.sh#shell.sh</file>
<capture-output/>
</shell>
<ok to="email-66c2"/>
<error to="Kill"/>
</action>
<action name="email-66c2">
<email xmlns="uri:oozie:email-action:0.2">
<to>myemail@mycompany.com</to>
<subject>job status</subject>
<body>job status ${wf:actionData('shell-05e6')['filePath']}</body>
<content_type>text/plain</content_type>
<attachment>${wf:actionData('shell-05e6')['filePath']},${wf:actionData('shell-05e6')['filePath1']}</attachment>
</email>
<ok to="End"/>
<error to="Kill"/>
</action>
<end name="End"/>
现在,如果其中一个位置的文件没有filepath
或filepath1
,则电子邮件操作失败。
无论文件是否存在,我想要的是我希望电子邮件操作成功
答案 0 :(得分:1)
写shell动作。
#!/bin/sh
#Need to write a code to find out file path. and assign to "fP".
echo "filePath=$fP" #Here "fP" is dynamically assign file path.
您可以捕获shell脚本的输出并将其传递给电子邮件操作。在shell脚本中,回显属性,如'filePath = $ fP',并在shell操作中添加capture-output元素。这将允许您从shell脚本捕获filePath。在电子邮件操作中,您可以将捕获的变量作为参数传递为$ {wf:actionData('shellAction')['filePath']},其中shellAction是shell操作名称。
电子邮件行动:
<attachment>${wf:actionData('shellAction')['filePath']}</attachment>
答案 1 :(得分:1)
可以有两种方法来解决新的需求。
方法#1 在shell Action和电子邮件操作之间添加条件操作
Shell Action就像:
path=/user/$USER/logging/${TIMESTAMP}/status/${TIMESTAMP}.fail_log
path1=/user/$USER/logging/`date -d "-1 days" '+%Y-%m-%d'`/status/`date -d "-1 days" '+%Y-%m-%d'`.fail_log
if [ -e "$path" ] && [ -e "$path1"]
then
echo filePath=$path,$path1
elif [ -e "$path" ]
then
echo filePath=$path
elif [ -e "$path1" ]
then
echo filePath=$path1
else
echo filePath=""
fi
条件行动将如下:
if filePath = "" then
call email_0 action # which has NO attachment tag.
else
call email_2 action # which has attachment tag with two files.
end if
在有条件的操作下,您将有两个电子邮件操作。
<attachment>${wf:actionData('shell-05e6')['filePath']}</attachment>
”和方法#2 无条件操作。
Shell Action就像:
path=/user/$USER/logging/${TIMESTAMP}/status/${TIMESTAMP}.fail_log
path1=/user/$USER/logging/`date -d "-1 days" '+%Y-%m-%d'`/status/`date -d "-1 days" '+%Y-%m-%d'`.fail_log
if [ -e "$path" ] && [ -e "$path1"]
then
echo filePath=$path,$path1
elif [ -e "$path" ]
then
echo filePath=$path
elif [ -e "$path1" ]
then
echo filePath=$path1
else
echo filePath="/user/$USER/logging/No_Status_log.fail_log" # this is default file with no data. You have to create it only one time.
fi
在这种方法中,尽管没有数据可用,但总会有一个文件附加。