Linux脚本实现文件系统使用率大于90%报警
disk_used.sh
#!/bin/bash
#Author:ztj
#Date:2023/5/6
#Description:磁盘使用率大于90%报警
NULLFILE=65
disk_filesystem=/tmp/filesystem.txt
> $disk_filesystem
df -h |grep -v "Filesystem" |grep -E "^/dev" >$disk_filesystem
if [ ! -s $disk_filesystem ];then
echo "$disk_filesystem is empty,please check it!"
exit $NULLFILE
else
while read line
do
if [ -n "$line" ];then
name_disk=$(echo $line | awk '{print $1}')
# echo $name_disk
used_disk=$(echo $line | awk '{print $5}' | tr -d %)
# echo $used_disk
if [ $used_disk -gt 90 ];then
echo "WARNING:the usage of $name_disk is above 90%."
fi
else
exit 0
fi
done <$disk_filesystem
fi