#!/usr/bin/ksh
#
# What= @(#) alert_tbs.sh V1.0 le 07/03/96 
# Script Surveillance tablespace temporaires 
#
ORACLE_SID=$1; export ORACLE_SID
ORACLE_HOME=/logiciel/oracle/oracle_7015; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH 
#
if [ -f /logiciel/oracle/oracle_$ORACLE_SID ]
then
	if test -z "$1" -o -z "$2"
	then
		echo "Usage: $0  <instance> pourcentage"
		exit 1
	fi
	VAL=`sqlplus system/manager << ! | grep Valeur | awk '{print $2}'
	set heading off;

	select ' Valeur',count(distinct tablespace_name)
	from sys.dba_tablespaces t
	where tablespace_name in ( select f.tablespace_name from sys.dba_data_files f,
	sys.dba_free_space s where f.tablespace_name = s.tablespace_name and
	f.tablespace_name like '%_W%'
	group by f.tablespace_name 
	having trunc(((sum(s.bytes)/count(distinct f.file_id))*100)/
	 (sum(f.bytes)/count(distinct block_id)),2)  <$2 )
	;
	exit;
	!`
	/logiciel/OpC/opcmon $3=$VAL
else
	/logiciel/OpC/opcmon $3=0
fi
