由于IP为动态,每次IP变化qb的端口需要重启才能通
#!/bin/bash
# 设置错误立即退出(避免部分失败仍继续执行)
set -e
# 检查端口状态
port=$(nmap -p 62333 $(curl -6s ipv6.ip.sb) -6 | grep '/tcp' | awk '{print $2}')
echo "[$(date)] qBittorrent 端口状态为:$port"
# 判断是否需要重启
if [[ "$port" == "open" ]]; then
echo "[$(date)] 端口开放,无需重启"
else
echo "[$(date)] 端口关闭,正在重启 qBittorrent..."
systemctl restart qb
fi
添加执行权限:
chmod +x /root/restartqb.sh
添加定时:
crontab -e
*/10 * * * * /root/restartqb.sh >> /var/log/qb_check.log 2>&1