Skip to content Skip to sidebar Skip to footer

Find The Latest Log File From Multiple Servers

For our daily monitoring we need to access 16 servers of a particular application and find the latest log file on one of those servers (it usually generates on the first 8). The p

Solution 1:

Create the list first and then find the max.

import glob
import os
import re

paths = [r'\\Server1\Logs\*.log',
         r'\\Server2\Logs\*.log',
         .....
         r'\\Server16\Logs\*.log']

list_of_files = []
for path in paths:
    list_of_files.extend(glob.glob(path))

if list_of_files:
    latest_file = max(list_of_files, key=os.path.getctime)
    f = open(os.path.join(latest_file), "r")
    print(latest_file)
else:
    print("No log files found!")

Post a Comment for "Find The Latest Log File From Multiple Servers"