Shell 硬盘监控
来源:互联网 发布:产品原型软件 编辑:程序博客网 时间:2024/04/30 09:04
用shell 写了一个硬盘监控的小程序
最后必须以 fi 来结尾闭合 if,fi 就是 if 倒过来拼写,后面也会遇见。
注意:expression 和方括号([ ])之间必须有空格,否则会有语法错误。
#!/bin/bash
MAX=95
EMAIL=zonghua@iyunshu.com
PART=sda1
IP=`ifconfig |grep -w "broadcast"|awk '{print $2}'`
use=`df -h | grep $PART | awk '{print $5}'| cut -d'%' -f1`
if [ $use -ge $MAX ]; then
echo "$IP have $use%" | mail -s "Running out of disk space" $EMAIL
fi
使用了一下命令
1. " ` " 它也被称为反引号 后引号(backquotes)或是斜引号(backticks).
命令替换.`command` 结构 使字符(`) 执行结果能赋值给一个变量。
(这个字符不是单引号,而是在标准美国键盘上的ESC键下面,在字符1左边,在TAB键上面的那个键,要特别留心)
(这个字符不是单引号,而是在标准美国键盘上的ESC键下面,在字符1左边,在TAB键上面的那个键,要特别留心)
例子:
A=`ls -l` 把ls -l的结果赋给A ls -l 作为命令来执行IP=`ifconfig |grep -w "broadcast"|awk '{print $2}'` 把一系列命令结果赋值给IP
2 if 命令.
f 语句通过关系运算符判断表达式的真假来决定执行哪个分支。Shell 有三种 if ... else 语句:
- if ……then... fi 语句;
- if ……then... else ... fi 语句;
- if ...then…… elif ...then……elif ...then…… else ... fi 语句。
1) if ... else 语句
if ... else 语句的语法:if [ expression ]then Statement(s) to be executed if expression is truefi如果 expression 返回 true,then 后边的语句将会被执行;如果返回 false,不会执行任何语句。
最后必须以 fi 来结尾闭合 if,fi 就是 if 倒过来拼写,后面也会遇见。
注意:expression 和方括号([ ])之间必须有空格,否则会有语法错误。
2) if ... else ... fi 语句
if ... else ... fi 语句的语法:if [ expression ]then Statement(s) to be executed if expression is trueelse Statement(s) to be executed if expression is not truefi如果 expression 返回 true,那么 then 后边的语句将会被执行;否则,执行 else 后边的语句。
) if ... elif ... fi 语句
if ... elif ... fi 语句可以对多个条件进行判断,语法为:if [ expression 1 ]then Statement(s) to be executed if expression 1 is trueelif [ expression 2 ]then Statement(s) to be executed if expression 2 is trueelif [ expression 3 ]then Statement(s) to be executed if expression 3 is trueelse Statement(s) to be executed if no expression is truefi哪一个 expression 的值为 true,就执行哪个 expression 后面的语句;如果都为 false,那么不执行任何语句。
3.数值比较符号
阅读全文
0 0
- Shell 硬盘监控
- linux服务器硬盘监控-shell脚本
- Shell脚本监控Linux系统硬盘各分区使用率
- 硬盘监控
- 监控shell
- shell 监控
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- 【转载】linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- shell脚本: linux系统的负载与CPU、内存、硬盘、用户数监控
- 利用Shell脚本来监控Linux系统的负载、CPU、内存、硬盘、用户登录数
- 监控硬盘剩余空间
- smartctl----硬盘状态监控
- IOSTAT监控硬盘状态
- smartctl----硬盘状态监控
- 使用JNotify监控硬盘
- 硬盘监控选购
- 监控硬盘和普通硬盘的差别
- VNC 远程桌面 连接(安装桌面程序)
- linux下安装svn,svn搭建,svn迁移详解
- 还是端口回流问题 TCP协议解析
- 外网访问oracle 很慢
- Shell 小程序演示
- Shell 硬盘监控
- 2Nginx+keepalive+2tomcat 故障转移
- Mysql 用户管理
- java鬼混笔记:lucene 7、查询排序和分页
- 安装python 第三方库(whl,py格式)
- Shell 统计导出数据 awk 里使用shell变量 参数
- awk sed 命令
- java AWT实现画图功能
- Python 调用 Shell命令