【发布时间】:2016-03-14 05:51:53
【问题描述】:
我尝试修改一个检查磁盘空间使用情况的小脚本,但遇到以下错误:
disk_space.sh: line 32: [: Use: integer expression expected
# Set alert limit, 90% we remove % for comparison
alert=90
# $1 is the partition name
# $5 is the used percentage
# Print the df -h, then loop and read the result
df -h | awk '{ print $1 " " $5 }' | while read output;
do
#echo $output
# Get partition name
partition=$(echo $output | awk '{ print $1 }')
#echo 'Partition: ' $partition
# Used space with percentage
useSpPer=$(echo $output | awk '{ print $2}')
#echo 'Used space %: ' $useSpPer
#used space (remove percentage)
useSp=$(echo -n $useSpPer | head -c -1)
#echo 'Used space digit: ' $useSp
# Recap
#echo $useSp ' has ' $partition
# -ge is greatter than or equal
if [ $useSp -ge $alert ]; then # THIS LINE 32
echo $partition 'is running out of space with '$useSpPer
#else
#echo 'Down'
fi
done
如果有人有想法,请提前感谢并感谢
【问题讨论】: