Update print.py
Browse files
print.py
CHANGED
@@ -1,20 +1,23 @@
|
|
|
|
1 |
import time
|
2 |
|
3 |
def read_and_print_file():
|
|
|
|
|
|
|
|
|
4 |
try:
|
5 |
-
with open(
|
6 |
content = file.read()
|
7 |
print("File Content:\n", content)
|
8 |
-
except FileNotFoundError:
|
9 |
-
print("Error: File '/etc/searxng/settings.yml' not found.")
|
10 |
except PermissionError:
|
11 |
-
print("Error: Permission denied to read
|
12 |
except Exception as e:
|
13 |
print(f"An unexpected error occurred: {e}")
|
14 |
|
15 |
# 定时任务,每隔10秒打印一次
|
16 |
-
interval = 10 #
|
17 |
-
print("Starting task. Press Ctrl+C to stop.")
|
18 |
try:
|
19 |
while True:
|
20 |
read_and_print_file()
|
|
|
1 |
+
import os
|
2 |
import time
|
3 |
|
4 |
def read_and_print_file():
|
5 |
+
filepath = '/etc/searxng/settings.yml'
|
6 |
+
if not os.path.exists(filepath):
|
7 |
+
print(f"Error: {filepath} does not exist.")
|
8 |
+
return
|
9 |
try:
|
10 |
+
with open(filepath, 'r') as file:
|
11 |
content = file.read()
|
12 |
print("File Content:\n", content)
|
|
|
|
|
13 |
except PermissionError:
|
14 |
+
print(f"Error: Permission denied to read {filepath}.")
|
15 |
except Exception as e:
|
16 |
print(f"An unexpected error occurred: {e}")
|
17 |
|
18 |
# 定时任务,每隔10秒打印一次
|
19 |
+
interval = 10 # 时间间隔(秒)
|
20 |
+
print("Starting task to print file content. Press Ctrl+C to stop.")
|
21 |
try:
|
22 |
while True:
|
23 |
read_and_print_file()
|