2017-05-03 32 views
0

我使用oozie發送帶附件的電子郵件。我正在做如下。根據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>[email protected]</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>[email protected]</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"/> 

現在,如果在該位置的一個沒有文件說,無論是filepathfilepath1,則電子郵件操作失敗。

我要的是不論文件是否存在或不是我想要的電子郵件的行動是成功的

+0

讓我知道你最喜歡哪種方法。 –

回答

1

有可能有兩個辦法來解決新requriement。

方法#1 添加殼行動和電子郵件行動之間有條件行動

殼牌的行動會是這樣的:

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 

在條件操作下方,您將有兩個電子郵件操作。

  1. 帶附件標籤 「<attachment>${wf:actionData('shell-05e6')['filePath']}</attachment>」 和
  2. 沒有依附標籤

方法2沒有條件操作。

殼牌的行動會是這樣的:

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 

在這種方法中,總是支持eventhough不附加任何數據avaliable一個文件。

+0

只是想知道你會遵循哪種方法。 –

+0

我更喜歡第二種方法 – User12345

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> 
+0

你能看看編輯的問題 – User12345