Surbao commited on
Commit
9ef4922
·
verified ·
1 Parent(s): ff61295

Create print.py

Browse files
Files changed (1) hide show
  1. print.py +26 -0
print.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
24
+ time.sleep(interval)
25
+ except KeyboardInterrupt:
26
+ print("\nTask stopped.")