#!/bin/ksh
# TGorman 19may09 - per MetaLink note #271855.1
#
. $HOME/.profile > /dev/null 2>&1
#
_Out=/tmp/run_aqcoalesce_$$.out
_Dir=`dirname $0`
#
${ORACLE_HOME}/bin/sqlplus "/ as sysdba" << __EOF__ > ${_Out} 2>&1
whenever oserror exit failure rollback
whenever sqlerror exit failure rollback
set echo on feedback on timing on serveroutput on size 1000000
spool /tmp/run_aqcoalesce
exec aqcoalesce
exit success commit
__EOF__
if (( $? != 0 ))
then
	mailx -s "`hostname`: run_aqcoalesce.sh $*" someone@anywhere.com < ${_Out}
	echo "`date`: $0 failed" > ${_Dir}/run_aqcoalesce.log
	rm -f /tmp/run_aqcoalesce*.*
	exit 1
fi
#
echo "`date`: $0 OK" > ${_Dir}/run_aqcoalesce.log
tail -300 ${_Dir}/run_aqcoalesce.log > /tmp/run_aqcoalesce_$$.tmp
mv /tmp/run_aqcoalesce_$$.tmp ${_Dir}/run_aqcoalesce.log
#
rm -f /tmp/run_aqcoalesce*.*
#
exit 0

