summaryrefslogtreecommitdiffstats
path: root/data_hacks/run_for.py
diff options
context:
space:
mode:
Diffstat (limited to 'data_hacks/run_for.py')
-rw-r--r--data_hacks/run_for.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/data_hacks/run_for.py b/data_hacks/run_for.py
index df7630e..08883b4 100644
--- a/data_hacks/run_for.py
+++ b/data_hacks/run_for.py
@@ -9,6 +9,7 @@ http://github.com/bitly/data_hacks
"""
import time
import sys
+import os
def getruntime(arg):
if not arg:
@@ -17,12 +18,14 @@ def getruntime(arg):
base = int(arg[:-1])
if suffix == "s":
return base
- elif suffix == "h":
+ elif suffix == "m":
return base * 60
+ elif suffix == "h":
+ return base * 60 * 60
elif suffix == "d":
- return base * 60 * 24
+ return base * 60 * 60 * 24
else:
- print >>sys.stderr, "invalid time suffix %r" % arg
+ print >>sys.stderr, "invalid time suffix %r. must be one of s,m,h,d" % arg
def run(runtime):
end = time.time() + runtime
@@ -35,8 +38,15 @@ def run(runtime):
return
if __name__ == "__main__":
+ usage = "Usage: tail -f access.log | %(prog)s [time] | ..." % os.path.basename(sys.argv[0])
+ help = "time can be in the format 10s 10m 10h etc"
+ if sys.stdin.isatty():
+ print usage
+ print help
+ sys.exit(1)
+
runtime = getruntime(sys.argv[-1])
if not runtime:
- print >>sys.stderr, "usage: tail -f access.log | run_for.py 10s | wc -l"
+ print usage
sys.exit(1)
run(runtime) \ No newline at end of file