Skip to content

Instantly share code, notes, and snippets.

@JustinAzoff
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinAzoff/37337b8dc70ca4da9808 to your computer and use it in GitHub Desktop.
Save JustinAzoff/37337b8dc70ca4da9808 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import sys
import time
SIZE_TIMEOUT = 10
def get_size(f):
for x in range(SIZE_TIMEOUT):
try:
size = os.stat(f).st_size
return size
except OSError:
time.sleep(1)
return os.stat(f).st_size
def is_growing(f):
size = get_size(f)
time.sleep(1)
for x in range(SIZE_TIMEOUT):
time.sleep(1)
newsize = get_size(f)
if newsize != size:
return True
return False
def is_growing_with_retries(f):
"""Check to see if a file is growing, with retries
this should handle the case when a file gets rotated mid check
"""
for x in range(3):
if is_growing(f):
return True
return False
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage %s filename" % sys.argv[0]
sys.exit(1)
f = sys.argv[1]
res = is_growing_with_retries(f)
if not res:
print "%s is not growing" % f
sys.exit(not res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment