Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (55 sloc) 1.62 KB
#!/usr/bin/env python
# Copyright 2010
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
Pass through data for a specified amount of time
import time
import sys
import os
def getruntime(arg):
if not arg:
suffix = arg[-1]
base = int(arg[:-1])
if suffix == "s":
return base
elif suffix == "m":
return base * 60
elif suffix == "h":
return base * 60 * 60
elif suffix == "d":
return base * 60 * 60 * 24
print >>sys.stderr, "invalid time suffix %r. must be one of s,m,h,d" % arg
def run(runtime):
end = time.time() + runtime
for line in sys.stdin:
if time.time() > end:
if __name__ == "__main__":
usage = "Usage: tail -f access.log | %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
runtime = getruntime(sys.argv[-1])
if not runtime:
print usage
Something went wrong with that request. Please try again.