Created
February 17, 2015 11:44
-
-
Save jschmid1/d8987045eb7aa8a02434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fileutils' | |
| dir = '/mnt' | |
| def write_file(size_in_mb, dir) | |
| File.open("#{dir}/file-#{rand(100000)}.txt", 'w') do |f| | |
| contents = "x" * (1024*1024) | |
| size_in_mb.times { f.write(contents) } | |
| end | |
| end | |
| write_file(50, dir) | |
| # bash solution | |
| #du = `du -hc #{dir}| tail -n 1 | grep -Eo [0-9]` | |
| # ruby solution | |
| du = `du -c #{dir}`.split(' ').first.to_i | |
| # bash solution | |
| #max_size = `df -h #{dir} | grep -Eo [0-9] | head -n 1` | |
| # ruby solution | |
| max_size = `df #{dir}`.split(' ')[-5].to_i | |
| while(1) do | |
| if max_size - 5000 >= du | |
| write_file(50, dir) | |
| puts 'write stuff' | |
| else | |
| puts 'delete all the stuff' | |
| Dir.glob("#{dir}/**/*").select {|f| File.file? f}.each { |d| File.delete(d)} | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment