#!/bin/bash

# Copyright 2005, IBM Corporation

# Do report for all collaboration areas.


# Usage of the file
if [[ $# -ne 3 ]]
then
 echo "Usage "
 echo $0 " --db=databasename --dbuser=touser --dbpassword=touserpassword"
 echo "Example " $0 " --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1"

 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
RepFile=`date |awk '{print "ghost_items_reports/report_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`;export RepFile

# Creating Logs Directory
mkdir -p ghost_items_reports

db2 connect to ${DBName} user ${DBUSER} using ${DBUserPassword}
db2 "select coa_id from coa" |grep -v COA_ID |grep -v "\-\-"|grep -v record > coaid.txt
db2 terminate

for CollabID in `cat coaid.txt`

do
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Starting Cleanup of Collab Area ID ${CollabID}"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

./clean_ghost_items_db2.sh --db=${DBName} --dbuser=${DBUSER} --dbpassword=${DBUserPassword} --collabid=${CollabID} --reportfile=${RepFile}_${CollabID}

echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Cleanup of Collab Area ID ${CollabID} is done"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

done
