Created
February 13, 2018 04:14
-
-
Save charasyn/3d919592301b84d2b0619aa9f337986c to your computer and use it in GitHub Desktop.
A script to monitor a file's size. Run with `monitor-file-size.py file-to-monitor`.
This file contains 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
#!/usr/bin/env python3 | |
# A script to monitor a file's size. | |
# Cooper Harasyn, 2018-02-12 | |
import time | |
import os | |
import sys | |
def Main(args): | |
if len(args) != 2: | |
print("Usage: {} <filename>".format(args[0])) | |
return 1 | |
delay = 1 # second | |
path = args[1] | |
prevSize = os.path.getsize(path) | |
counter = 0 | |
while counter < 5: | |
size = os.path.getsize(path) | |
diff = size-prevSize # Bytes | |
rate = diff/delay # Bytes / seconds | |
oneM = 1048576 | |
print("size: {0:10.2f}MB\trate: {1:6.2f}MB/s".format(size/oneM,rate/oneM)) | |
if diff == 0: | |
counter += 1 | |
else: | |
counter = 0 | |
time.sleep(delay) | |
prevSize = size | |
if __name__ == "__main__": | |
sys.exit(Main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment