Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report