Created
August 29, 2013 16:27
-
-
Save RoxasShadow/6380334 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
| INTERFACE = ARGV[0] || 'wlan0' | |
| class Float; def to_mb; self / 1048576; end; end | |
| initial = (ARGV[1] || 0 ).to_f | |
| available = (ARGV[2] || 100).to_f | |
| delay = (ARGV[3] || 5 ).to_f | |
| left = 0 | |
| initial = File.read('.band') if !ARGV[1] && File.exists?('.band') | |
| trap('INT') do | |
| File.open('.band', ?w) { |f| f.write left.to_s } | |
| abort | |
| end | |
| while true | |
| begin | |
| tx = File.read("/sys/class/net/#{INTERFACE}/statistics/tx_bytes").to_f.to_mb | |
| rx = File.read("/sys/class/net/#{INTERFACE}/statistics/rx_bytes").to_f.to_mb | |
| left = (tx + rx + initial) - available | |
| puts "#{(left).round(4)}mb left" | |
| rescue | |
| puts "Waiting for #{INTERFACE}..." | |
| end | |
| sleep delay | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment