2017-05-03 5 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>のワークフローでは、日付が常に変更されます。

ワークフローが呼び出されたときに、その特定の日の添付ファイルを送信する変数を渡すにはどうすればよいですか。

編集した質問。

私のシェルスクリプト:

#!/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"/> 

の場所の一つで、何のファイルが存在しない場合filepathまたはfilepath1どちらかと言うその後、電子メールアクションが失敗しています。

は、私が欲しいのは、私は電子メールのアクションが

+0

あなたが最も好きなアプローチを教えてください。 –

答えて

1

新しいrequriementを解決するには、2つのアプローチがあるかもしれません。

アプローチ#1 とシェルのアクションは次のようになります

シェルアクションと電子メールアクションの間で条件付きアクションの追加:

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 
:条件付きアクションのようにようになる

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 

条件付きアクションの下で2つの電子メールアクションがあります。条件付きアクションなし取付タグ

アプローチ#2せず取付タグ "<attachment>${wf:actionData('shell-05e6')['filePath']}</attachment>" と

    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="/user/$USER/logging/No_Status_log.fail_log" # this is default file with no data. You have to create it only one time. 
      fi 
      

      、データなしavaliable本家取り付けられた1つのファイルがなかれます。

  • +0

    あなたが従う方法を知りたいだけです。 –

    +0

    私は2番目のアプローチがより好きです – User12345

    1

    ライトシェルアクション成功になりたいかかわらず、ファイルが存在するかどうかにはありません。

    #!/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. 
    

    シェルスクリプトの出力をキャプチャして電子メールアクションに渡すことができます。シェルスクリプトで、 'filePath = $ fP'のようなプロパティをエコーし​​、シェルアクションにcapture-output要素を追加します。これにより、シェルスクリプトからfilePathを取得できます。電子メールアクションでは、取得した変数を$ {wf:actionData( 'shellAction')['filePath']}のようにパラメータとして渡すことができます。ここで、shellActionはシェルアクション名です。

    電子メールアクション:

    <attachment>${wf:actionData('shellAction')['filePath']}</attachment> 
    
    +0

    編集した質問をご覧ください。 – User12345

    関連する問題