import datetime, re, sys # Function to read log file and extract the run time def check_run_time(log_file_path, delta): try: #Set timezone info timezone_offset = +10.0 # Pacific Standard Time (UTC−08:00) tzinfo = datetime.timezone(datetime.timedelta(hours=timezone_offset)) #Number of minutes allowable difference in last logged run vs current time #delta = 10 # Read the log file with open(log_file_path, 'r') as file: lines = file.readlines() # Extract the run time line run_time_line = next(line for line in lines if "Run time" in line) # Parse the run time from the line run_time_str = re.search(r'Run time: (.+)', run_time_line).group(1) # Convert run time string to datetime object run_time = datetime.datetime.strptime(run_time_str, "%a %b %d at %H:%M") # Update the run time to the current year since log doesn't contain the year run_time = run_time.replace(tzinfo=tzinfo,year=datetime.datetime.now(tzinfo).year) # Get the current time current_time = datetime.datetime.now(tzinfo) # Calculate the time difference time_difference = current_time - run_time # Check if the run time is within the last 10 minutes if time_difference <= datetime.timedelta(minutes=delta): return "OK" else: return "FAIL" except Exception as e: return f"Error: {str(e)}" # Path to the log file log_file_path = sys.argv[1] delta = int(sys.argv[2]) # Check the run time and print the result status = check_run_time(log_file_path, delta) print(status)