Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop in Bash until reaching free disk space limit?

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 x; y; z; done;

but I guess my while syntax is wrong.

like image 221
David B Avatar asked Feb 25 '23 09:02

David B


1 Answers

( ) 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;
like image 195
andcoz Avatar answered Mar 05 '23 18:03

andcoz