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.") |