You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
539 B
Bash

#!/bin/bash
while true; do
# 寻找 Python 进程并杀死
sleep 1800
pids=$(pgrep -f "python main.py")
if [ -n "$pids" ]; then
echo "Killing Python processes with PIDs: $pids"
# 获取当前时间
current_time=$(date "+%Y-%m-%d %H:%M:%S")
# 使用循环逐个杀死进程
for pid in $pids; do
kill "$pid"
echo "Restart at $current_time" >> log.txt # 将信息追加到log.txt文件中
done
else
echo "Python process not found."
fi
done