On 2/11/23 11:03, Gunnar Lindholm wrote:
10 feb. 2023 kl. 23:09 skrev Bernhard Voelker <m...@bernhard-voelker.de>:
On 2/3/23 20:58, Gunnar Lindholm wrote:
+With the @option{-b} and @option{-f} options one can use the exit status to
+verify the available space (in bytes or percentage) with a command like
+@samp{if df -b 640000 /var/log ; then echo "That is big enough for everyone";
fi}
a) The functionality can easily be achieved via scripting, e.g. using the
--output option
and sed(1):
$ if test 80 -gt `df --output=pcent / | sed '1d;s/%//'`; then echo FINE; else
echo TOO_FULL; fi
TOO_FULL
[...] it as an advantage to keep sed out of if-statements and make them less
complicated.
That was just one example with sed(1); there are dozens of alternatives,
including pure shell
pattern replacement.
Probably one would wrap that into an alias, a function or a wrapper shell
script anyway ...
$ cat ~/bin/df-pct-lower
#!/bin/sh
x="$( df --output=pcent "$1" | sed '1d;s/[% ]*//g' )" \
&& test "$x" \
|| { echo "$0: error: failed to determine df percentage: '$1'" >&2; exit 1;
}
test "$x" -lt "$2"
so the details don't show up in the business logic:
$ df-pct-lower / 80; echo $?
1
$ df-pct-lower / 90; echo $?
0
Have a nice day,
Berny