# IBM Confidential
# OCO Source Materials
# 5724-V51
#
# (c) Copyright IBM Corp. 2000, 2008 All Rights Reserved.
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.

#!/bin/bash

#      doconsolereportblob.sh - Do report for one collaboration area, whose associated workflow is an item workflow.

#	Copyright 2007, IBM Corporation

#

# Usage of the file
if [[ $# -ne 5 ]]
then
 echo "Usage "
 echo "doconsolereportblob.sh --db=databasename --dbuser=dbusername --dbpassword=dbuserpassword --srcCtgId=srcCtgId  --outfile=filename"
 echo "Example: doconsolereportblob.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --srcCtgId=6 --outfile=foo.txt"
  
 exit 0
fi


# Declare the variables
DBName=`echo $1 |cut -d "=" -f2`;export DBName
DBUSER=`echo $2 |cut -d "=" -f2`;export DBUSER
DBUserPassword=`echo $3 |cut -d "=" -f2`;export DBUserPassword
SrcCtgId=`echo $4 |cut -d "=" -f2`;export SrcCtgId
OutFile=`echo $5 |cut -d "=" -f2`;export Outfile


ReportFile="${SrcCtgId}-{`date |awk '{print "report_item_ca_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`-.txt";export ReportFile
sed s/"srcCtgId"/"${SrcCtgId}"/ $TOP/src/integrity/SQL/oracle/reportblob.sql > reportblob_scratch.sql


sqlplus -s ${DBUSER}/${DBUserPassword}@${DBName} <<EOF
--set heading off;
--set linesize 80;
--set pagesize 0;
--set feedback off;
@$TOP/src/integrity/SQL/oracle/procs
spool tempreport.txt;
@reportblob_scratch
spool off
EOF

mv tempreport.txt  ${OutFile}
rm reportblob_scratch.sql

exit $?
 


