Last active
December 14, 2015 06:59
-
-
Save adimania/5046792 to your computer and use it in GitHub Desktop.
A simple tailer to send the data to remote machine using UDP. It was originally written to ship logs to logstash but it can be used to ship any text anywhere.
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/python | |
from time import sleep | |
import socket | |
log=open("somefile.log","r") | |
log.readlines() | |
pos=log.tell() # This is the last line of the file | |
while True: | |
line=log.readline() | |
if line: | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # I like UDP to send the logs. | |
sock.sendto(line, ("localhost", 7897)) | |
pos=log.tell() # save the current position so that tailer can resume from here. | |
else: | |
sleep(1) # I don't want to check too soon. Sleep for 1 sec. | |
log=open("somefile.log","r") | |
log.seek(pos) # Resume the position saved last. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment