此代码工作我的系统上。也许检查一下,以确保dh
的输出始终加起来大于85.你可能会有更多的成功,而不是对dh使用-h参数,而是以字节为单位检索实际的数字,然后对其进行操作。
#!/bin/sh
# Change this number accordingly as usual
MAX=100000000
EMAIL="[email protected]"
PART=sda1
USE=$(df | grep $PART | awk '{ print $3 }')
if [ "$USE" -gt "$MAX" ]
then echo "Successful"
#echo "Percent used: $USE of /" | mail -s "Server is running out of disk space" $EMAIL
fi
或为百分比也许尝试POSIX shell字符串切割:
#!/bin/sh
MAX=85
EMAIL="[email protected]"
PART=sda1
USE=$(df | grep $PART | awk '{ print $5 }')
if [ "${USE%%%}" -gt "$MAX" ]
then echo "Successful"
#echo "Percent used: $USE of /" | mail -s "Server is running out of disk space" $EMAIL
fi
我无法重现这一点。将'set -x'添加到脚本中。 – Cyrus
也是'grep | awk |切“是反模式; http://www.iki.fi/era/unix/award.html#grep – tripleee