ORACLE

ORACLE
Let us share our knowledge to the world of oracle apps. I am trying my best to do so and I request every one to contribute their part. If you have any thing useful related to oracle apps, do send me I will post in my blog on behalf of you. If you like my blog tell the world about it, else tell me i will improve. You can suggest me, what exactly you want on oracle apps. Mail your queries.

Thursday, February 7, 2013


Shell Script-Move files from one dir and another dir , Mail sending and zero size file check


#!/bin/ksh
################################################################################
# Copyright (c) 2013 Motorola
################################################################################
# System      : Asia ERP
# Subsystem   : Transfer AR to BaaN
# Date        : 22-Jan-13
# Version     : 1.0
# Author(s)   : Hari Basker I
# Title       : AR Interface to BaaN
# Purpose     : Move Flat File To CUSTAR Folder
# Input Param : $1  - Concurrent Parameter String
# Parameters  : 1 - FILE_NAME              (mandatory)
#    2 - Source Dir (mandatory)
#               3 - Destination Dir (mandatory)
#  
################################################################################
# Change History
#
# Date      Done By  Ref   Description
# --------- -------  ----- ------------------------------------------------------
# 22-JAN-2013 Hari    Initial Revision
################################################################################

PARAMETERS=$1
FILE_NAME=`echo $PARAMETERS | cut -f9 -d" " | sed 's/"//g'`
eval SOURCE_PATH=`echo $PARAMETERS | cut -f10 -d" " | sed 's/"//g'`
eval DESTINATION_DIR=`echo $PARAMETERS | cut -f11 -d" " | sed 's/"//g'`
eval MAILING_LIST=`echo $PARAMETERS | cut -f12 -d" " | sed 's/"//g'`

#####################################################################################
echo  "************************Parameters*****************************************\n

        Data Directory          : $SOURCE_PATH
        Destination Directory   : $DESTINATION_DIR
        File Name               : $FILE_NAME
 Mailing List        : $MAILING_LIST

        ****************************************************************************
        "



getMailList()
{
                sqlplus -s /nolog <<!!|grep -v 'Connected'
                connect ${FCP_LOGIN};
                SET HEADING OFF;
                SET FEEDBACK OFF;
                SET LINESIZE 3000;
                SET SERVEROUTPUT ON SIZE 1000000;
                BEGIN
                DECLARE
                         lv_mailing_list                VARCHAR2(2000) := '';
                         BEGIN
                             BEGIN
              select TO_RECIPIENTS into  lv_mailing_list
              from alr_distribution_lists
              where name ='${MAILING_LIST}';
                                  EXCEPTION
                                  WHEN NO_DATA_FOUND  THEN
                                        DBMS_OUTPUT.PUT_LINE('NO_DATA_FOUND');
                                  WHEN OTHERS THEN
                                        DBMS_OUTPUT.PUT_LINE('ERROR');
                             END;

                              DBMS_OUTPUT.PUT_LINE(lv_mailing_list);
                     END;
                END;
/
!!
}
value=`getMailList`

if [ -d "${SOURCE_PATH}" ] ; then
:
else
echo " Invalid data directory : $SOURCE_PATH"
  exit 1
fi
if [ -d "${DESTINATION_DIR}" ] ; then
:
else
echo " Invalid Destination directory : $DESTINATION_DIR"
exit 1
fi


if [ -f "${SOURCE_PATH}/${FILE_NAME}" ] ; then
   if [ -s "${SOURCE_PATH}/${FILE_NAME}" ] ; then
mv ${SOURCE_PATH}/${FILE_NAME} ${DESTINATION_DIR}
if [ $? = "0" ] ; then
 echo "File ${FILE_NAME} is successfully moved from ${SOURCE_PATH} to ${DESTINATION_DIR}"
else
 echo "Error : File moving process"
fi
   else
     echo "File is zero size : ${SOURCE_PATH}/${FILE_NAME}"
     echo "File is zero size : ${SOURCE_PATH}/${FILE_NAME}" | mail -s "File is not generated" ${value}
     rm ${SOURCE_PATH}/${FILE_NAME}
   fi
else
    echo "File is not Found!"
    echo "File is not found" | mail -s "File is not found" ${value}
fi

No comments:

Post a Comment