1

I need to check if I Filesystem exists, and if it does exist there is 300 MB of space in it.

What I have so far:

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

This throws an error. I don't really know what I'm doing in shell.

My highest priority is AIX but I'm trying to get it to work for HP and Sun too.

Please help.

-Alex

2 Answers 2

1

Here is the code I got working.

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
0

How about posting the error? Anyway, try the following syntax, ie. double brackets and no double quotes:

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

From man bash:

[[ expression ]]

Return a status of 0 or 1 depending on the evaluation of the conditional expression expression.

1
  • The OP is probably using sh which doesn't have [[. Although ksh does have it if that's what's being used. Apr 10, 2010 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.