English 中文(简体)
Trying to test space in filesystem on Unix
原标题:

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

最佳回答

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
问题回答

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.





相关问题
Portable way to get file size (in bytes) in the shell

On Linux, I use stat --format="%s" FILE, but the Solaris machine I have access to doesn t have the stat command. What should I use then? I m writing Bash scripts and can t really install any ...

Unix: fast remove directory for cleaning up daily builds

Is there a faster way to remove a directory then simply submitting rm -r -f *directory* ? I am asking this because our daily cross-platform builds are really huge (e.g. 4GB per build). So the ...

Startup time in Solaris server using shell script

How to find the start up time of a Solaris 5.1 server using a shell script,need to know how much time it took to be on running state?I need to know how much time it took to come to running mode from ...

Ruby 1.8.6 BigDecimal.to_f always returns 0,0 on Solaris

I have come across a very weird error. I m on Solaris 10, using Ruby Enterprise Edition (ruby 1.8.6 (2008-08-08 patchlevel 286) [i386-solaris2.10]) with Rails 2.3.4. I have a very weird error. In irb: ...

Where to set JDK to be used for SunOne server?

Where to set the JDK to be used by the SunOne server on Solaris? Is it all configured via an environment variable like JDK_HOME or JAVA_HOME, or is there a config file for the SunOne server somewhere ...

热门标签