#/bin/bash
#該腳本用于統計硬盤空間和表空間的使用情況,并郵件發出
#初始化環境變量
source /home/oracle/.bash_profile
#獲得本機ip
ip=`/sbin/ifconfig eth0 | grep Bcast | cut -d : -f 2 | cut -d " " -f 1`
#切換到本腳本目錄
cd /home/oracle/shell/
#刪除之前該腳本產生的日志文件
rm -rf $ip.txt
#統計硬盤空間
echo -e "您好!
$ip統計信息如下:/n/n" >> $ip.txt
echo "硬盤空間統計:" >> $ip.txt
/bin/df -Th >> $ip.txt
#統計表空間
echo -e "/n/n/n表空間統計:" >> $ip.txt
sqlplus -s scott/tiger << EOF >> $ip.txt
set feed off
set lines 400
set pages 900
col 表空間名 for a20
select x.tablespace_name 表空間名,已用,已分配,已用占已分配的比例,空閑的已分配空間,最大可用空間,已分配占最大可用比例,可自動擴展的空間
from (select TABLESPACE_NAME,round(sum(BYTES) / 1024 / 1024 / 1024, 9) 已分配,
round(sum(MAXBYTES - BYTES) / 1024 / 1024 / 1024,2) 可自動擴展的空間,
round(sum(MAXBYTES) / 1024 / 1024 / 1024) 最大可用空間,
to_char(round(sum(BYTES) / sum(MAXBYTES) * 100, 2), '990.99') || '%' 已分配占最大可用比例
from dba_data_files
group by TABLESPACE_NAME) x,
(select a.tablespace_name,
round(a.bytes / 1024 / 1024 / 1024, 9) 已用,
round(b.bytes / 1024 / 1024 / 1024, 9) 空閑的已分配空間,
to_char(round(a.bytes / (a.bytes + b.bytes) * 100, 2),
'990.99') || '%' 已用占已分配的比例
from sys.sm/$ts_used a, sys.sm/$ts_free b
where a.tablespace_name = b.tablespace_name) y
where x.tablespace_name = y.tablespace_name
order by 1;
exit
EOF
#把統計結果郵件發出
mutt -s "$ip統計信息" --
[email protected] < $ip.txt