monitordisk.sh如下
复制代码 代码如下:
#!/bin/bash
#Updated:2008-03-03 PM By:leif(liangliwen@163.com)
EMAIL=/usr/local/bin/email
/bin/df -h >/tmp/df.txt
USE=`df -H | grep -o [0-9]*% | grep -o ‘[0-9]\+'`
for i in $USE
do
if (( $i > 95 ))
then
$EAMIL -s “WARNING Low disk space for $i” liangliwen@163.com break
fi
if (( $i > 90 ))
then
$EMAIL -s “Low disk space for $i” liangliwen@163.com fi
done
/bin/rm -f /tmp/df.txt
实现目的,任何一个分区使用到90%就发送一个邮件给指定的收件人,到95%就在邮件主题出警告(warning),说明发送邮件程序EMAIL,是从http://www.cleancode.org/projects/email 下载安装,比较灵活.
把这个shell根据需要放在crontab 实现定时检查磁盘情况
以下是补充内容:
用于监视远程主机磁盘使用情况的shell脚本,文件名:disklog.sh
复制代码 代码如下:
#!/bin/bash
# 文件名:disklog.sh
# 用途:监视远程系统的磁盘使用情况
logfile="diskusage.log"
if [[ -n $1 ]]
then
logfile=$1
if
if [ ! -e $logfile ]
then
printf "%-8s %-14s %-9s %-8s %-6s %-6s %-6s %s\n" "Date" "IP ADDRESS" "Device" "Capacity" "Used" "Free" "Percent" "Status" > $logfile
fi
IP_LIST="127.0.0.1 0.0.0.0"
# 提供远程主机IP地址列表
(
for ip in $IP_LIST
do
ssh slynux@$ip 'df -H' | grep ^/dev/ > /tmp/$$.df
while read line;
do
cur_date=$(date +%D)
printf "%-8s %-14s " $cur_date $ip
echo $line | awk '{ printf("%-9s %-8s %-6s %-6s %-8s", $1,$2,$3,$4,$5); }'
pusg=$(echo $line | egrep -o "[0-9]+%")
pusg=${pusg/\%/};
if [ $pusg -lt 80 ];
then
echo SAFT
else
echo ALERT
fi
done< /tmp/$$.df
done
)>>$logfile
我们可以用cron以固定的间隔来调度脚本执行,例如在crontab中加入如此条目,以实现每天上午10点自动运行脚本:
00 10 * * * /home/sh/disklog.sh /home/log/diskusg.log
执行crontab -e命令,添加上面一行内容并保存。
也可以手动执行:
$ ./disklog.sh
最近发表
- Centos7 metasploit-framework安装部署
- 记录systemd内存占用过多
- 错误提示open_basedir restriction in effect. File is not within the allowed path:的解决方法
- EUserv自动续期shell脚本配合crontab
- Elasticsearch 7.9.1集群安装配置
- 判断磁盘空间使用率是否达到阈值shell脚本
- TypeError: Unicode-objects must be encoded before hashing
- Unverified HTTPS request is being made
- Centos7 部署DHCP服务
- LVS负载调度NAT及DR教程
标签列表
- win11 (20)
- win11教程 (20)
- win11桌面 (1)
- 远程桌面 (1)
- 远程链接 (1)
- 清理缓存 (1)
- Win11如何设置右键经典模式 (2)
- Win11右键怎么设置原来的模样 (2)
- Win11图标 (2)
- Win11 (4)
- 本地磁盘 (1)
- win11正式版退回win10 (1)
- win10 (1)
- 管理员权限 (1)
- 帝国cms教程 (36)
- 火焰效果 (2)
- 火焰制作 (2)
- 火焰动图 (2)
- ps教程 (9)
- Office 2010 (2)
- Office2010 (2)
- Office2010激活 (2)
- Office2007 (4)
- Office2007安装 (4)
- Office2007激活 (4)
