您可以使用 Python 的 schedule 库来定时运行脚本。首先,确保您已经安装了 schedule 库。您可以使用以下命令来安装它:

pip install schedule

然后,创建一个 Python 脚本,并使用以下代码来定时运行 systemctl 命令:

import schedule
import time
import os

def restart_service():
    os.system('systemctl restart SecureTunnel')

# 每 21 分钟运行一次脚本
schedule.every(21).minutes.do(restart_service)

while True:
    schedule.run_pending()
    time.sleep(1)

保存脚本,并在后台运行它,它将每 21 分钟执行一次systemctl restart SecureTunnel命令。请注意,您需要以管理员权限运行脚本,以便能够执行 systemctl 命令。

使用 Python 定时重启 SecureTunnel 服务

原文地址: https://www.cveoy.top/t/topic/phMD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录