Linux 和 macOS:用 cron 每周更新
把下面的内容保存为 ~/.aria2/update-trackers.sh:
#!/bin/sh
# Replace (or add) the bt-tracker line in aria2.conf with the current best public trackers.
CONF="${CONF:-$HOME/.aria2/aria2.conf}"
LIST=$(curl -fsSL https://cdn.jsdelivr.net/gh/ngosang/trackerslist@master/trackers_best.txt | grep -v '^$' | paste -sd, -) || exit 1
[ -n "$LIST" ] || exit 1
if grep -q '^bt-tracker=' "$CONF"; then
sed -i.bak "s#^bt-tracker=.*#bt-tracker=$LIST#" "$CONF"
else
echo "bt-tracker=$LIST" >> "$CONF"
fi
然后运行 crontab -e,加入这一行,每周一 04:00 自动执行:
0 4 * * 1 sh $HOME/.aria2/update-trackers.sh