监视磁盘分区使用情况的bash脚本 [英] bash script that monitor a disk partition's usage
本文介绍了监视磁盘分区使用情况的bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
df表演
-bash-4.1# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 1918217320 1783986384 36791092 98% /
tmpfs 16417312 0 16417312 0% /dev/shm
/dev/sda1 482214 148531 308784 33% /boot
/dev/sdb1 1922858352 1373513440 451669312 76% /disk2
我需要对bash脚本编写脚本,如果分区100%充满,该函数将返回1.如何才能做到这一点?我可以使用哪些命令来解析df的输出?
I need to bash script a function that returns 1 if an paritions become 100% full. how can this be done? what commands can I use to parse out the output of df?
推荐答案
不是过度拥护和笨拙的忠实拥护者,因为随着时间的推移,它确实会带来错误.
Not a huge fan of excessive greps and awks as it can really bring errors over time..
我只获取重要文件夹的信息.以下是使用stat的示例,它将为您提供文件夹中的可用BYTES,然后将其转换为MB(10 ** 6).我在RHEL6.x系统上对此进行了粗略的测试.
I would just get the information for the folders that matter. Below is a sample of using stat which will give you the available BYTES in a folder, then converts it to MB (10**6). I roughly tested this on my RHEL6.x system.
folder_x_mb=$(($(stat -f --format="%a*%s" /folder_x)/10**6))
folder_y_mb=$(($(stat -f --format="%a*%s" /folder_y)/10**6))
folder_z_mb=$(($(stat -f --format="%a*%s" /folder_z)/10**6))
这篇关于监视磁盘分区使用情况的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文