import os os.system("docker logs flydog-sdr > /home/flydog/logs/logs.txt") file_output = open(r"/home/flydog/logs/out.txt", "r") file_input = open(r"/home/flydog/logs/logs.txt", "r") while(True): last_line = file_output.readline() if not last_line: break last = last_line file_output.close() found = 0 while(True): line = file_input.readline() if line == last: found = 1 break else: found = 0 if not line: break if found == 0: file_input.close() file_input = open(r"/home/flydog/logs/logs.txt", "r") file_output = open(r"/home/flydog/logs/out.txt", "a") while(True): lines = file_input.readline() if not lines: break index_A = lines.find("ARRIVED") index_B = lines.find("LEAVING") index_C = lines.find("Alert_") index_SNR = lines.find("SNR-measure") if index_SNR >= 0: index_A = -1 index_B = -1 index_C = -1 if index_A >= 0: file_output.write(lines) if index_B >= 0: file_output.write(lines) if index_C >= 0: file_output.write(lines) file_output.close() file_input.close() os.remove('/home/flydog/logs/logs.txt')