本文最后更新于 334 天前,其中的信息可能已经有所发展或是发生改变。
SHELL 脚本
- 因为自己机器过多,CLASH的问题会导致IP上限,故写了这个脚本
main.sh
mkdir -p ~/nnr-api
cat > ~/nnr-api/main.sh << EOF
#!/bin/bash
# 环境判断
if [ -z "$(command -v jq)" ]; then
if [ -x "$(command -v apt-get)" ]; then
apt-get -y install jq || { echo "Error installing jq"; exit 1; }
elif [ -x "$(command -v yum)" ]; then
yum -y install jq || { echo "Error installing jq"; exit 1; }
else
echo "Error: Unsupported package manager" >&2
exit 1
fi
fi
# 初始化变量
work_dir="$(cd $(dirname $0);pwd)"
nnr_token="替换成自己的token"
i="0"
# 获取所有规则
curl -s -X POST -H "Content-Type: application/json" -H "token: ${nnr_token}" https://nnr.moe/api/rules > ${work_dir}/rules
[ $? -eq 0 ] && echo "success" || { echo "false"; exit; }
# 获取所有规则rid
[ -f ${work_dir}/result ] && rm -rf ${work_dir}/result
while true :
do
name=$(cat ${work_dir}/rules | jq -r .data[$i].name)
rid=$(cat ${work_dir}/rules | jq -r .data[$i].rid)
[ "${rid}" == "null" ] && break
echo "\"${name}\" ${rid}"
echo "${rid}" >> ${work_dir}/result
((i++))
sleep 0.5
done
# 重启所有规则
while read line
do
curl -X POST -H "Content-Type: application/json" -H "token: ${nnr_token}" https://nnr.moe/api/rules/restart -d '{"rid": "'"${line}"'"}'
echo -e "\nrestart ${line}"
sleep 0.5
done < ${work_dir}/result
EOF
chmod +x ~/nnr-api/main.sh
运行与Crontab
运行
~/nnr-api/main.sh
crontab
- 每天凌晨4点全部重启
0 4 * * * root /bin/bash ~/nnr-api/main.sh