Skip to content

Instantly share code, notes, and snippets.

@turtiesio
Created November 9, 2022 08:46
Show Gist options
  • Save turtiesio/6644b0dd5571cac9179631bd0f9f47ff to your computer and use it in GitHub Desktop.
Save turtiesio/6644b0dd5571cac9179631bd0f9f47ff to your computer and use it in GitHub Desktop.
using tail -F, keep track of log file even log rotation happens
import subprocess
def tail(filename: str) -> Generator[str, None, None]:
proc = subprocess.Popen(["tail", "-F", filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if line:
yield line.decode("utf-8")
else:
break
for line in tail("/config/logs/openssh/current"):
print(line.strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment