Count the usage of hard disk space and tablespace, and send an email

Source: Internet
Author: User

Count the usage of hard disk space and tablespace, and send an email

#/Bin/bash
# This script is used to count the usage of the hard disk space and tablespace, and is sent by email

# Initializing Environment Variables
Source/home/oracle/. bash_profile

# Obtain the local ip Address
Ip = '/sbin/ifconfig eth0 | grep Bcast | cut-d:-f 2 | cut-d ""-f 1'

# Switch to the script directory
Cd/home/oracle/shell/

# Delete the log files generated by the script
Rm-rf $ip.txt

# Counting hard disk space
Echo-e "Hello!
$ Ip statistics: \ n "> $ip.txt
Echo "Hard Disk Space statistics:"> $ip.txt
/Bin/df-Th> $ip.txt

# Statistical table space
Echo-e "\ n tablespace statistics:"> $ip.txt
Sqlplus-s scott/tiger <EOF> $ip.txt
Set feed off
Set lines 400
Sets pages 900
Col tablespace name for a20
Select x. tablespace_name table space name, used, allocated, used as the allocated proportion, idle allocated space, maximum available space, allocated as the maximum available proportion, and automatically scalable Space
From (select TABLESPACE_NAME, round (sum (BYTES)/1024/1024/1024, 9) allocated,
Round (sum (MAXBYTES-BYTES)/1024/1024/, 2) automatically scalable space,
Maximum available space of round (sum (MAXBYTES)/1024/1024/1024,
To_char (round (sum (BYTES)/sum (MAXBYTES) * 100, 2), '192. 99') | '%' 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) used,
Round (B. bytes/1024/1024/1024, 9) idle allocated space,
To_char (round (a. bytes/(a. bytes + B. bytes) * 100, 2 ),
'192. 99') | '%' percentage of used resources in allocated resources
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

# Send the statistical result email
Mutt-s "$ ip Statistics" -- zhangwz@xx.net <$ip.txt

Added to the scheduled task of the operating system:
Execute this script at every Friday.
[Oracle @ ~] $ Crontab-l
30 15 ** 5/home/oracle/shell/weekcheck. sh

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.