Created
November 9, 2022 08:46
-
-
Save turtiesio/6644b0dd5571cac9179631bd0f9f47ff to your computer and use it in GitHub Desktop.
using tail -F, keep track of log file even log rotation happens
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
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