The shell script realizes the hard disk space and the table space usage statistics and the mail informs the _linux shell

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.