Copy Code code as follows:
#/bin/bash
#该脚本用于统计硬盘空间和表空间的使用情况, and Mail out
#初始化环境变量
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 "Hello!"
$IP statistics are as follows: \ n ">> $ip. txt
echo "Hard disk space statistics:" >> $ip. txt
/bin/df-th >> $ip. txt
#统计表空间
ECHO-E "\n\n\n Table Space Statistics:" >> $ip. txt
Sqlplus-s scott/tiger << EOF >> $ip. txt
Set Feed off
Set Lines 400
Set pages 900
Col table space name for A20
Select X.tablespace_name table space name, used, allocated, used to account for allocated proportions, free allocated space, maximum free space, allocated maximum available proportions, space automatically expanded
From (select Tablespace_name,round (SUM (BYTES)/1024/1024/1024, 9) is allocated,
Round (sum (maxbytes-bytes)/1024/1024/1024,2) can automatically expand the space,
Round (sum (maxbytes)/1024/1024/1024) Maximum free space,
To_char (Round) (SUM (BYTES)/SUM (maxbytes) * 100, 2), ' 990.99 ') | | '% ' has been allocated to the maximum available percentage
From Dba_data_files
Group by Tablespace_name) x,
(Select A.tablespace_name,
Round (a.bytes/1024/1024/1024, 9) has been used,
Round (b.bytes/1024/1024/1024, 9) Free allocated space,
To_char (Round (a.bytes/a.bytes + b.bytes) * 100, 2),
' 990.99 ') | | '% ' used to account for allocated proportions
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 Statistics"--zhangwz@xx.net < $ip. txt
Added to the operating system's scheduled tasks:
Execute this script every Friday 15:30
Copy Code code as follows:
[oracle@ ~]$ Crontab-l
* * 5/home/oracle/shell/weekcheck.sh