I would like to do a set of operations (x y z
) as long as I have at least 200MB free space on file-system mounted to /media/z
.
How can I do that?
I tried something like
while (`df | grep /media/z | awk '{print $4}'` > 204800); do开发者_Python百科 x; y; z; done;
but I guess my while
syntax is wrong.
( )
executes a command in a sub-shell. If you want to test a condition you have to use test command: [ ]
.
while [ `df | grep /media/z | awk '{print $4}'` -gt 204800 ]; do
x; y; z; sleep 5;
done;
if you're using bash use [[ ]] to use the internal testing, it's faster and gives you standard operators:
while (( $(df /media/z | awk 'NR==2{print $4}') > 204800 )); do
x; y; z
done
精彩评论