我编写了一个 bash 脚本来验证硬盘驱动器的使用情况,并在使用情况达到容量百分比时发送通知:
#!/bin/bash
Name=$(hostname)
current_usage=$( df -h | grep '/dev/sda5' | awk {'print $5'} )
max_usage=65%
if [ ${current_usage%?} -ge ${max_usage%?} ]; then
mailbody="Hard drive is running out of space at Virtual Machine ${Name}. Current usage: ${current_usage}."
echo ${mailbody} | mail -s "Hard Drive Usage Alert" root
fi
该脚本在 Ubuntu 20.04 的虚拟机中运行时运行良好
但是,如果在 Ubuntu 18.04 中运行,我会收到以下消息:
/etc/cron.daily/df-check:
/etc/cron.daily/df-check: line 7: [: -ge: unary operator expected
知道为什么会发生这种情况吗?
谢谢。