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