巴什监控磁盘使用情况 [英] Bash monitor disk usage
本文介绍了巴什监控磁盘使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我买了它具有的Debian减少版本就可以了NAS设备。
据跑出了一天的空间,我不知道。我基本上想要写一个bash脚本每当盘获得超过90%满,这将提醒我。
是任何人都知道一个脚本,将做到这或给我写一个?
一些建议解决方案
#!/斌/庆典
源/ etc / profile文件#设备进行检查
DEVNAME =的/ dev / sdb1的令p =`DF -k $ DEVNAME | grep的-v ^文件| AWK'{printf的(%i的,$ 3 * 100 / $ 2); }'`
如果[$ P -ge 90]
然后
DF -h $ DEVNAME |邮件-s空间不足my@email.com
科幻
crontab的这不论你想要一个警报运行
编辑:对于多盘
#!/斌/庆典
源/ etc / profile文件#设备检查
DEVNAMES =的/ dev / SDB1的/ dev / sda1的在$ DEVNAMES DEVNAME
做
令p =`DF -k $ DEVNAME | grep的-v ^文件| AWK'{printf的(%i的,$ 3 * 100 / $ 2); }'`
如果[$ P -ge 90]
然后
DF -h $ DEVNAME |邮件-s$ DEVNAME空间不足my@email.com
科幻
DONE
I bought a NAS box which has a cut down version of debian on it.
It ran out of space the other day and I did not realise. I am basically wanting to write a bash script that will alert me whenever the disk gets over 90% full.
Is anyone aware of a script that will do this or give me some advice on writing one?
解决方案
#!/bin/bash
source /etc/profile
# Device to check
devname="/dev/sdb1"
let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'`
if [ $p -ge 90 ]
then
df -h $devname | mail -s "Low on space" my@email.com
fi
Crontab this to run however often you want an alert
EDIT: For multiple disks
#!/bin/bash
source /etc/profile
# Devices to check
devnames="/dev/sdb1 /dev/sda1"
for devname in $devnames
do
let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'`
if [ $p -ge 90 ]
then
df -h $devname | mail -s "$devname is low on space" my@email.com
fi
done
这篇关于巴什监控磁盘使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文