Linux/Unix shell 脚本监控磁盘可用空间
来源:互联网 发布:建筑企业财务报表数据 编辑:程序博客网 时间:2024/04/29 18:10
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、对于超出阙值的情形发送邮件并且附上当前服务器上磁盘空间的使用情况。
Forward from http://blog.csdn.net/leshami/article/details/8893943
0 0
- Linux/Unix shell 脚本监控磁盘可用空间
- Linux/Unix shell 脚本监控磁盘可用空间
- Linux/Unix shell 脚本监控磁盘可用空间
- 采用Shell及AWK脚本实现磁盘使用空间监控
- Linux---服务器CPU 内存 磁盘 监控SHELL脚本
- shell编程磁盘监控(评估可用空间耗尽时间,邮件通知管理员)
- linux 查看目录的剩余可用空间【shell脚本】
- Ubuntn shell脚本之磁盘流量监控
- 监控linux中CPU 内存 磁盘数据的shell脚本(图文)
- linux-shell脚本,监控nginx,tomcat,redis,php-cli,磁盘状态
- linux df 监控磁盘空闲空间
- linux shell脚本-监控进程
- linux shell脚本监控端口
- shell脚本监控磁盘I/O,cpu,内存
- shell脚本监控磁盘I/O,cpu,内存
- HP Unix 主机内存监控告警shell脚本
- Unix/Linux 磁盘 I/O 性能监控命令iostat
- Unix/Linux 磁盘 I/O 性能监控命令iostat
- [!] Pod::Executable pull的解决办法
- Java里快如闪电的线程间通讯
- deb 打包
- Java为什么要设置环境变量?
- 软件开发模式对比(瀑布、迭代、螺旋、敏捷)
- Linux/Unix shell 脚本监控磁盘可用空间
- js判断字符长度及中英文数字的例子
- 如何阅读源代码
- dede5.7无法更新栏目与 HTML文档
- linux下gdal的搭建
- vtk显示属性、窗口以及交互设置
- unity3d能应用到什么领域
- 一个简单的jQuery插件ajaxfileupload实现ajax上传文件例子
- SAP下载SE78的图片