试图在Unix上的文件系统中测试空间

时间:2010-03-22 18:38:22

标签: shell solaris aix hp-ux

我需要检查文件系统是否存在,如果它确实存在,则其中有300 MB的空间。

到目前为止我所拥有的:

if [ "$(df -m /opt/IBM | grep -vE '^Filesystem' | awk '{print ($3)}')" < "300" ]
then
echo "not enough space in the target filesystem"
exit 1
fi

这会引发错误。我真的不知道我在做什么。

我的最高优先级是AIX,但我也试图让它为HP和Sun工作。

请帮忙。

-Alex

2 个答案:

答案 0 :(得分:1)

这是我工作的代码。

if [ "$(df -m /opt/IBM/ITM | awk 'NR==2{print ($3)}')" -lt "300" ]
then
    echo "not enough space in the target filesystem"
    exit 1
fi

答案 1 :(得分:0)

发布错误怎么样?无论如何,尝试以下语法,即。双括号,没有双引号:

if [[ $(...) < 300 ]]; then
    ...
fi

来自 man bash

[[表达]]

根据条件的评估,返回0或1的状态 表达表达。