Get the App
SLTechnology News&Howtos  ›  Development  › 

Use Shell script to realize the usage statistics of hard disk space and table space and notify by mail.

Shulou Source: shulou.com Published: 2022-06-03 19:16:11 11月12日 Update

This article mainly explains the "use of Shell script to achieve hard disk space and table space usage statistics and email notification", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "use Shell script to achieve hard disk space and table space usage statistics and email notification" bar!

The code is as follows:

# / bin/bash

# this script is used to count the usage of hard disk space and table space, and send out e-mail

# initialize environment variables

Source / home/oracle/.bash_profile

# get native ip

Ip= `/ sbin/ifconfig eth0 | grep Bcast | cut-d:-f 2 | cut-d ""-f 1`

# switch to this script directory

Cd / home/oracle/shell/

# Delete log files generated by the script before

Rm-rf $ip.txt

# Statistics of hard disk space

Echo-e "Hello!

The ip statistics are as follows:\ n\ n "> > $ip.txt

Echo "hard disk space statistics:" > $ip.txt

/ bin/df-Th > > $ip.txt

# Statistical tablespace

Echo-e "\ n\ n\ ntablespace statistics:" > > $ip.txt

Sqlplus-s scott/tiger > $ip.txt

Set feed off

Set lines 400

Set pages 900

Col tablespace name for A20

Select x.tablespace_name table space name, used, allocated, used as allocated, free allocated space, maximum available space, allocated as maximum available percentage, automatically expandable space

From (select TABLESPACE_NAME,round (sum (BYTES) / 1024 / 1024 / 1024, 9) has been assigned

Round (sum (MAXBYTES-BYTES) / 1024 / 1024 / 1024jue 2) automatically expandable space

Round (sum (MAXBYTES) / 1024 / 1024 / 1024) maximum available 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') | |'% 'has been used as a percentage of allocated

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

# email the statistical results

Mutt-s "$ip Statistics"-- zhangwz@xx.net < $ip.txt

Add to the scheduled tasks of the operating system:

Execute this script at 15:30 every Friday

The code is as follows:

[oracle@ ~] $crontab-l

30 15 * 5 / home/oracle/shell/weekcheck.sh

Thank you for your reading, the above is the "use of Shell script to achieve hard disk space and table space usage statistics and email notification" of the content, after the study of this article, I believe you use Shell script to achieve hard disk space and table space usage statistics and email notification of this problem has a more profound experience, the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Space statistics scripts allocation hard disk situation mail maximum proportion learning code information content free hello operating system tasks variables that is ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple MySQL Shulou Technology MariaDB