Linux/Unix shell 脚本监控磁盘可用空间
Linux下监控磁盘的空闲空间的shell脚本,对于系统管理员或DBA来说,必不可少。下面是给出的一个监控磁盘空间空间shell脚本的样本,供大家参考。
1、监控磁盘的空闲空间shell脚本
- robin@SZDB:~/dba_scripts/custom/bin> more ck_fs_space.sh
- #!/bin/bash
- # ------------------------------------------------------------------------------+
- # CHECK FILE SYSYTEM SPACE BY THRESHOLD |
- # Filename: ck_fs_space.sh |
- # Desc: |
- # The script use to check file system space by threshold |
- # Once usage of the disk beyond the threshold, a mail alert will be sent. |
- # Deploy it by crontab. e.g. per 15 min |
- # Usage: |
- # ./ck_fs_space.sh <percent> </filesystem [/filesystem2]> |
- # |
- # Author : Robinson |
- # Blog : http://blog.csdn.net/robinson_0612 |
- # ------------------------------------------------------------------------------+
- #
- # -------------------------------
- # Set environment here
- # ------------------------------
- if [ -f ~/.bash_profile ]; then
- . ~/.bash_profile
- fi
- export host=`hostname`
- export mail_dir=/users/robin/dba_scripts/sendEmail-v1.56
- export mail_list='Robinson.cheng@12306.com'
- export mail_fm='oracle@szdb.com'
- tmpfile=/tmp/ck_fs_space.txt
- alert=n
- # --------------------------------
- # Check the parameter
- # --------------------------------
- max=$1
- if [ ! ${2} ]; then
- echo "No filesystems specified."
- echo "Usage: ck_fs_space.sh 90 / /u01"
- exit 1
- fi
- # --------------------------------
- # Start to check the disk space
- # --------------------------------
- while [ "${2}" ]
- do
- percent=`df -P ${2} | tail -1 | awk '{print $5 }' | cut -d'%' -f1`
- if [ "${percent}" -ge "${max}" ]; then
- alert=y
- break
- fi;
- shift
- done;
- # ------------------------------------------------------------------------
- # When a partition was above the threshold then send mail with df output
- # ------------------------------------------------------------------------
- if [ ! "${alert}" = 'n' ];then
- df -h >$tmpfile
- mail_sub="Disk usage beyond the threshold ${max} on ${host}."
- $mail_dir/sendEmail -u ${mail_sub} -f $mail_fm -t $mail_list -o message-file=${tmpfile}
- fi;
- exit;
2、脚本说明
a、该脚本使用了 sendEmail 工具来发送邮件。
b、使用方式为"Usage: ck_fs_space.sh 90 / /u01" 。
c、脚本中使用了一个while循环来逐个判断所有的指定分区的空闲空间是否超出阙值。
d、对于超出阙值的情形发送邮件并且附上当前服务器上磁盘空间的使用情况。
转:http://blog.csdn.net/leshami/article/details/8893943
Linux/Unix shell 脚本监控磁盘可用空间的更多相关文章
- linux实现shell脚本监控磁盘内存达到阈值时清理catalina.out日志
想在服务器上写一个shell脚本,在磁盘使用率达到80%时,自动清理掉一些没有用的日志文件,根据这个想法,在生产环境上写了一个以下脚本,按照该流程,可实现在linux环境做一个定时任务来执行shell ...
- Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间
Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...
- Linux/Unix shell 脚本中调用SQL,RMAN脚本
Linux/Unix shell脚本中调用或执行SQL,RMAN 等为自动化作业以及多次反复执行提供了极大的便利,因此通过Linux/Unix shell来完成Oracle的相关工作,也是DBA必不可 ...
- Linux使用shell脚本监控
(1)性能监控脚本 performance.sh #!/bin/bash #-------------------------------------------------------------- ...
- zabbix 调用python脚本监控 磁盘剩余空间(创建模版,创建监控项,创建触发器)
主要 记录一下 使用zabbix 自己创建模版.监控项.触发器,并调用python脚本. 需求: 监控备份机磁盘剩余空间(windows系统) 一.安装zabbix_agent 比较简单 修改配置文 ...
- Linux/Unix shell 监控Oracle监听器(monitor listener)
使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linu ...
- Linux/Unix shell 监控Oracle告警日志(monitor alter log file)
使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linu ...
- Linux/Unix shell 监控Oracle实例(monitor instance)
使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linu ...
- Linux/Unix shell sql 之间传递变量
灵活结合Linux/Unix Shell 与SQL 之间的变量传输,极大程度的提高了DBA的工作效率,本文针对Linux/Unix shell sql 之间传递变量给出几个简单的示例以供参考. Lin ...
随机推荐
- SqlBulkCopy大批量数据插入到sql表中
alter TYPE TableType AS TABLE ( Name VARCHAR() , code VARCHAR() ) GO alter PROCEDURE usp_InsertProdu ...
- C/C++类型转换
1.隐式类型转换 1.1 隐式类型转换的规则 K & R A.6.5 Arithmetic Conversions(数值型间的转换)First, if either operand is lo ...
- iOS 开发--添加工程
文/Bison(简书作者)原文链接:http://www.jianshu.com/p/dd71e15df5d0著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 第一部分,配置项目 在此只 ...
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-005Spring-Data-JPA例子的代码
一.结构 二.Repository层 1. package spittr.db; import java.util.List; import org.springframework.data.jpa. ...
- Struts2笔记——与ServletAPI解耦
与ServletAPI解耦的访问方式 为了避免与 Servlet API 耦合在一起, 方便 Action 做单元测试, Struts2 对 HttpServletRequest, HttpSessi ...
- html5 语音搜索
开始以为是接口什么的,原来这就是语言搜索. 只需要在input加上x-webkit-speech <input type="text" class="text&qu ...
- 开启MySQL慢查询日志
1.修改my.cnf或my.ini 1).linux----------------------------------- /etc/my.cnf 文件 [mysqld] long_query_ti ...
- 16_采用SharedPreferences保存用户偏好设置参数
按钮事件 <Button android:id="@+id/button" android:layout_width="wrap_content" and ...
- 纯java从apk文件里获取包名、版本号、icon
简洁:不超过5个java文件 依赖:仅依赖aapt.exe 支持:仅限windows 功能:用纯java获取apk文集里的包名,版本号,图标文件[可获取到流直接保存到文件系统] 原理:比较上一篇文章里 ...
- 下拉刷新控件(1)PullToRefreshList示例
有很多控件都可以下拉刷新如,ListView,ExpandableListView,GridView,ScrollView,ViewPager,WebView等, 其中最常见的是ListView.本文 ...