用shell脚本写一个查询centos7的系统可用空间

发布时间 2023-08-01 16:32:28作者: 非帅

#!/bin/bash
#by herofox qq:42845734
. /etc/profile
#通过显示系统空间,结合分割命令和awk命令来取数
sys=$( df -h |grep -w "centos-root" |awk '{ split ($5,sys,"%");print sys[1]}')
if [ $sys -gt 60 ] && [ $sys -lt 100 ]
then
echo '没有可用空间了,赶紧清理系统空间,还剩:'$sys'%'
sleep 5
sh /aisino/clean_tomcat_txt.sh
sleep 5
sh /aisino/clean_fwkp_log.sh
aftersys=$( df -h |grep -w "centos-root" |awk '{ split ($5,aftersys,"%");print aftersys[1]}')
echo '清理后,还剩:'$aftersys'%'
else
echo '可用空间足够,系统空间使用了:'$sys'%'
fi