我想在第5列'used%‘的基础上通过'df -h’检查磁盘利用率,我想要与某个阈值进行比较,比如'80‘。如果$5 >阈值,则输入到文件系统。
请任何人帮帮我。
发布于 2021-07-13 18:14:15
只有1个分支到df
类似于:
treshold=80
{ read _
while read dev tot use fre pct fs;do
if [ "${pct%\%}" -gt $treshold ] ;then
echo "Warning: $dev: $use/$tot use $pct on '$fs'"
fi
done
} < <(df -h)在脚本中,您可以使用:
#!/bin/bash
treshold=80
exec {dfout}< <(df -h)
read -u $dfout headline
while read -u $dfout dev tot use fre pct fs;do
if [ "${pct%\%}" -gt $treshold ] ;then
echo "Warning: $dev: $use/$tot use $pct on '$fs'"
fi
done
exec {dfout}<&-发布于 2021-07-13 17:54:13
for i in $(df -h |awk 'NR!=1 && $5>="80%" {print $6}');do echo $i;done或
for i in $(df -h |awk 'NR!=1 && $5>="80%" {print $6}')
do
echo $i
echo "Hello-World"
#and-do-this cd $i
#and-do-etc
donehttps://stackoverflow.com/questions/68358685
复制相似问题