Quantcast
Channel: Oracle Fusion Apps | Oracle Fusion | Oracle Apps Training
Viewing all articles
Browse latest Browse all 103

Sending Output of Concurrent Programs as Email Attachment

$
0
0

Sending Output Of Concurrent Programs Via Email  

While working on Oracle Applications E- Business Suite it is a very common requirement that we want to send the output of a concurrent program as an email attachment to specific email id.  

This requirement can be easily achieved by creating a shell script which will take the output file and send email to the subscribers.  

For this you have to follow the below mentioned steps:

a) Create a Executable with execution file type as Host.

b) Create a Concurrent program which will have parameters as Request ID(for normal request whose output is stored in fnd_concurrent requests) , Output Request ID ( for XML based concurrent requests where otput is stored in fnd_conc_request_outputs), Attachment type( ‘LOG’/’OUT’ for Log file and output file respectively, Email Id ( email id to whom request needs to be send, Email Subject (Email Subject)          

Now whenever you will call this concurrent program passing the correct parameters you will be able to send the output to email id.  

Moreover, in order to have the control you can have flexibility to control which concurrent programs output you want to send via email and the corresponding email id create a lookup  

Lookup Type : XXC_GET_SUBSCRIBERS  

Code : 10,20,30 ..etc

Meaning : 10,20,30...etc

Description : Concurrent program Name whose output needs to be send  

Tag : Email ID to which the concurrent program output will be send.  

Attaching the shell script program for ready reference.  

SendEmail

Please save the above file in desktop and open with textpad ,  wordpad, notepad.

#!/bin/sh
# *************************************************************************************************
# Filename: ebs2fusion_send_email.sh
# Author: Sandip
# Date Created: 14-OCT-2010
# Description: Send output/log File as an attachment
# Parameters: 1. Request ID
# 2. Output Request ID
# 2. Attachment Type: LOG / OUT
# 3. Email Ids
# 4. Email Subject
# History:
# Name Date Version Description
# --------------- ------------ ------- -----------------------
# Ashish 14-OCT-2010 1.0 Original Creation
# *************************************************************************************************

# -- ------------------------
# -- Extract input parameters
# -- ------------------------
USER_PWD=`echo $1|cut -d '"' -f2` # -- Database User/Pwd
USERNAME=`echo $1|cut -d '"' -f4` # -- UserName

REQ_ID=`echo $1|cut -d '"' -f8` # -- Request Id
OUT_REQ_ID=`echo $1|cut -d '"' -f10` # -- Output Request Id
ATTACHMENT_TYPE=`echo $1|cut -d '"' -f12` # -- Attachment Type
EMAIL_ID=`echo $1|cut -d '"' -f14` # -- Email Id
EMAIL_SUB=`echo $1|cut -d '"' -f16` # -- Email Subject

# -- ----------------------
# -- Print input parameters
# -- ----------------------
echo " "
echo "User Name: "$USERNAME
echo "Request Id: "$REQ_ID
echo "Output Request Id: "$OUT_REQ_ID
echo "Attachment Type: "$ATTACHMENT_TYPE
echo "Email Id: "$EMAIL_ID
echo "Subject: "$EMAIL_SUB
echo "---------------------------------------------------------------------------------------------"

# -- ----------------
# -- Email Validation
# -- ----------------
case $EMAIL_ID in
*@?*.?*) echo "Email Address Validated.";;
*) echo "Invalid Email Address. Please enter the correct format of email address and re-run the program";
exit 1;;
esac

if [ "$OUT_REQ_ID" == "" ]; then
echo "Fetching based on Request Id"
# -- -------------------------------------------
# -- Fetch OUT and LOG filename using Request ID
# -- -------------------------------------------
QUERY_OUTPUT=`sqlplus -s /nolog <<end_stmt1
set heading off
set feedback off
set verify off
set termout off
set pages 0

CONNECT $USER_PWD
SELECT fcq.status_code, length(fcq.logfile_name), length(fcq.outfile_name), fcq.logfile_name, fcq.outfile_name FROM fnd_concurrent_requests fcq WHERE fcq.request_id='${REQ_ID}';
end_stmt1`
else
echo "Fetching based on Output Request Id"
# -- -------------------------------------------
# -- Fetch OUT and LOG filename using Request ID
# -- -------------------------------------------
QUERY_OUTPUT=`sqlplus -s /nolog <<end_stmt1
set heading off
set feedback off
set verify off
set termout off
set pages 0

CONNECT $USER_PWD
SELECT fcq.status_code, length(fcq.logfile_name), length(fcro.file_name), fcq.logfile_name, fcro.file_name FROM fnd_concurrent_requests fcq, fnd_conc_req_outputs fcro WHERE fcq.request_id=fcro.concurrent_request_id AND fcq.request_id='${OUT_REQ_ID}';
end_stmt1`
fi

# -------------------------------------------------------------------
# -- Above query will return the value as
# -- 1. Connected. (If connected to DB)
# -- 2. Program Status (C or E)
# -- 3. Length of Log File Path and Name
# -- 4. Length of Output File Path and Name
# -- 5. Log File Path and Name
# -- 6. Output File Path and Name
# -------------------------------------------------------------------

# --------------------------------------
# -- Using cut command taking the values
# --------------------------------------
IS_CONNECTED_TO_DB=`echo $QUERY_OUTPUT|cut -d" " -f1`

if [ "$IS_CONNECTED_TO_DB" == "Connected." ]; then
#-- Getting the Program Status (C or E)
PROG_STATUS=`echo $QUERY_OUTPUT|cut -d" " -f2`
echo "PROGRAM Status: "$PROG_STATUS
else
echo "Error: Connecting to DB: "$QUERY_OUTPUT
exit 1
fi

# -------------------------------------------------
# -- Sending email
# -- LOG_FILE => Attaching the log file
# -- OUT_FILE => Attaching the output file
# -- EMAIL => Passing EMail id
# -- EMAIL_SUB => Subject of Email
# ------------------------------------------------
if [ "$ATTACHMENT_TYPE" == "OUT" ]; then
# -- Getting the output file (with path)
LEN_OUTPUT_FILE=`echo $QUERY_OUTPUT|cut -d" " -f4`
echo "Length of OUTPUT FILE: "$LEN_OUTPUT_FILE

OUTPUT_FILE=`echo $QUERY_OUTPUT|cut -d" " -f6`
echo "OUTPUT FILE: "$OUTPUT_FILE

if [ $LEN_OUTPUT_FILE -gt 80 ]; then
OUTPUT_FILE1=`echo $QUERY_OUTPUT|cut -d" " -f7`
echo "OUTPUT FILE1: "$OUTPUT_FILE1
OUTPUT_FILE=$OUTPUT_FILE$OUTPUT_FILE1
fi

echo "OUTPUT FILE: "$OUTPUT_FILE

# ---------------------------------------------------------------
# -- Sending EMail with output file attachment
# -- Using -e in echo command to print the file name in new line
# ---------------------------------------------------------------
#(echo -e "$EMAIL_BODY"; uuencode $OUTPUT_FILE OUTPUT_FILE_$REQ_ID.txt) | mail "$EMAIL_ID" -s "$EMAIL_SUB"

echo "$EMAIL_SUB"| mutt -a $OUTPUT_FILE "$EMAIL_ID" -s "$EMAIL_SUB"

echo "EMAIL has been sent with output file to $EMAIL_ID"

elif [ "$ATTACHMENT_TYPE" == "LOG" ]; then
# -- Getting the Log File (with Path)
LOG_FILE=`echo $QUERY_OUTPUT|cut -d" " -f5`

echo "LOG FILE: "$LOG_FILE

# ---------------------------------------------------------------
# -- Sending EMail with log file attachment
# -- Using -e in echo command to print the file name in new line
# ---------------------------------------------------------------
#(echo -e "$EMAIL_BODY"; uuencode $LOG_FILE LOG_FILE_$REQ_ID.txt) | mail "$EMAIL_ID" -s "$EMAIL_SUB"
#uuencode -m $LOG_FILE LOG_FILE_$REQ_ID.txt | mail "$EMAIL_ID" -s "$EMAIL_SUB"

echo "$EMAIL_SUB"| mutt -a $LOG_FILE "$EMAIL_ID" -s "$EMAIL_SUB"

echo "EMAIL has been sent with log file to $EMAIL_ID"
fi


Viewing all articles
Browse latest Browse all 103

Trending Articles