########################################################
#
# 功能:oracle数据库空间自动整理
# 作者:corer
# 时间:2007-11-01
#
# 命令行
# ksh tablespace.sh user password oracle_sid host_ip>oralce_tablespace.xls
#
#########################################################
get_tablespace()
{
sqlplus $user/$password@$oracle_sid<<!
set pagesize 1000;
set linesize 1000;
set head off;
select 'XXX'
||' '
||ff.s
||' '
||ff.b
||' '
||(ff.b - fr.b)
||' '
|| fr.b
||' '
||round((ff.b - fr.b) / ff.b * 100) || '%'
from (select tablespace_name s, sum(bytes) / 1024 / 1024/1024 b
from dba_data_files
group by tablespace_name) ff,
(select tablespace_name s, sum(bytes) / 1024 / 1024/1024 b
from dba_free_space
group by tablespace_name) fr
where ff.s = fr.s;
!
}
####################################################main###############################################################
user=$1
password=$2
oracle_sid=$3
host=$4
printf "%s/t%s/t%s/t%s/t%s/t%s/t%s/n" "主机名" "数据库名" "表空间名" "总空间(G)" "已使用(G)" "未使用(G)" "使用百份比"> ${oracle_sid}表空间统计.xls
get_tablespace|grep "XXX"|awk '{printf("%s/t%s/t%s/t%12f/t%12f/t%12f/t%s/n","'${host}'","'${oracle_sid}'",$2,$3,$4,$5,$6) } ' >>${oracle_sid}表空间统计.xls