File size: 781 Bytes
9ef4922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import time

def read_and_print_file():
    filepath = '/etc/searxng/settings.yml'
    if not os.path.exists(filepath):
        print(f"Error: {filepath} does not exist.")
        return
    try:
        with open(filepath, 'r') as file:
            content = file.read()
            print("File Content:\n", content)
    except PermissionError:
        print(f"Error: Permission denied to read {filepath}.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

# 定时任务,每隔10秒打印一次
interval = 10  # 时间间隔(秒)
print("Starting task to print file content. Press Ctrl+C to stop.")
try:
    while True:
        read_and_print_file()
        time.sleep(interval)
except KeyboardInterrupt:
    print("\nTask stopped.")