Monday, 6 May 2013

Inbount,Outbound Shell script

echo "Setting Parameters"
program=SHEll_PRO
userpass=`echo $1 | cut -f2 -d '"'`
user=`echo $userpass | cut -f1 -d '/'`
passwd=`echo $userpass | cut -f2 -d '/'`
reqid=`echo $1 | cut -f2 -d " " | cut -f2 -d "="`
usrid=`echo $1 | cut -f4 -d " " | cut -f2 -d "="`
################################
user_name=`sqlplus -s $userpass <<EXIT
set pages 0
set feed off
set verify off
select user_name from fnd_user where user_id=$usrid;
EXIT`
if  echo $user_name |grep "ORA-" > /dev/null
then
  echo "Error ... $user_name "
  exit 1
fi
echo user_name=$user_name
################################
get_directory_name()
{
sqlplus -s $userpass <<EXIT
set serverout on size 100000;
set pages 0
set feed off
set verify off
declare
l_err           varchar2(100);
l_name  varchar2(100);
Begin
mas_pa_bs_reverse_bill.get_dir_name('$file_lookup',l_name,l_err);
if l_err is not null then
   dbms_output.put_line('DIRECTORY_ERROR-'||l_err);
elsif l_name is null then
   dbms_output.put_line('Unable to get $file_type name');
else
   dbms_output.put_line(l_name);
end if;
end;
/
EXIT
}
################################
## ATT Location Address inbound directory is defined as NS_ATT_LOC_ADDR_IN
file_type='inbound directory'
file_lookup='AP_GTY_IN'
echo "Find $file_type name :lookup=$file_lookup"
inbound_dir=`get_directory_name`
if  echo $inbound_dir |grep "DIRECTORY_ERROR-" > /dev/null
then
  echo "Error ... $inbound_dir "
  exit 1
fi
echo inbound_dir=$inbound_dir
################################
## ATT Location Address error directory is defined as AP_GTY_ERR
file_type='inbound err directory'
file_lookup='AP_GTY_ERR'
echo "Find $file_type name :lookup=$file_lookup"
inbound_err_dir=`get_directory_name`
if  echo $inbound_err_dir |grep "DIRECTORY_ERROR-" > /dev/null
then
  echo "Error ... $inbound_err_dir "
  exit 1
fi
echo inbound_err_dir=$inbound_err_dir
################################
## ATT Location Address archive directory is defined as AP_GTY_ARCH
file_type='inbound archive directory'
file_lookup='AP_GTY_ARCH'
echo "Find $file_type name :lookup=$file_lookup"
inbound_arch_dir=`get_directory_name`
if  echo $inbound_arch_dir |grep "DIRECTORY_ERROR-" > /dev/null
then
  echo "Error ... $inbound_arch_dir "
  exit 1
fi
echo " start sqlload "
## SQLLDR SCRIPT
sqlldr $userpass control=$MAS_TOP/bin/TMS_TBL_CON.ctl data=$file.csv log=$inbound_dir/$file.log bad=$inbound_dir/$file.bad discard=$inbound_dir/$file.dis > $inbound_dir/sqlload_1 > $inbound_dir/sqlload_2
if [ ! $file.csv = $file_name ]
then
  mv $file.csv $file_name
fi

x=`date +"%m%d%y%H%M%S"`

echo " sqlload done, check for any errors"
if grep -i error $inbound_dir/sqlload_2 > /dev/null
then
     echo "********************************************************************************************************"
     echo "Error in Loading the file to the staging table for the file $file_name "
     echo "Error->$sqlload"
     echo "********************************************************************************************************"
     exit 1
elif [ -f $inbound_dir/$file.err ]
then
        echo "********************************************************************************************************"
      echo " *******  Error while Loading to the staging table for the file $file_name, please see the error file ******* "
        echo "********************************************************************************************************"
        echo "Moving the file $file_name to the error directory "
      mv $inbound_dir/$file_name $inbound_err_dir/$file_name.$x
fi
echo "Successfully loaded records from datafile $file_name"
echo
# Output Datafile row count
v_datafile_row_cnt=`wc -l $file_name | cut -f1 -d " " | tr -d " "`
v_datafile_row_cnt=`expr $v_datafile_row_cnt - 1`
echo "Moving data file $file_name to the Bank Reconciled Directory"
mv $inbound_dir/$file_name $inbound_arch_dir/$file_name.$x
echo " just sent the file: $inbound_dir/$file_name to $inbound_arch_dir/"
done
nil_report()
{
echo "No records to Process, exiting"
echo `date +"%r %a %d %h %Y " `  >> $repfile
echo "              No Files Found  " >> $repfile
echo "          ==============================================" >> $repfile
echo "        No records to Process" >> $repfile
}
echo " Bank Reconciled ended successfully"

No comments:

Post a Comment