@小小 大佬有话说 : 2020-1-2 04:46:03
关于cf自动开验证码问题
本帖最后由 @小小 于 2020-1-2 04:51 编辑
首先感谢大佬的博客:https://cangshui.net/4516.html
系统:CentOS Linux 7.2.1511 (Core)
宝塔日志:
cpu_load数值为:1579 ,cpu_maxload数值为:50
未开验证码
/www/server/cron/7ed4e366a7cd219a888c15dcb7fd726e: line 87: syntax error: unexpected end of file
:'( 大佬帮我看看哪里出问题了
https://s2.ax1x.com/2020/01/02/lJXZDg.png
部分代码
#==================================================#
mkdir "$cfile" 2>/dev/null
cpu_num=$( grep -c ‘model name’ /proc/cpuinfo ) #cpu总核数
cpu_load=$( uptime | awk ‘{print $10}’ | awk ‘{sub(/.$/,"")}1’ ) #系统1分钟的平均负载
cpu_load=$(echo "$cpu_load * 100" | bc | awk ‘{print int($0)}’ )
cpu_maxload=`expr $cpu_num * $maxload * 10`
nowtime=$(date +%s)
echo -e "cpu_load数值为:$cpu_load ,cpu_maxload数值为:$cpu_maxload"
if [[ $lasttime -eq "" ]]
then
echo -e "未开验证码"
else
echo -e "数据正常"
gaptime=`expr $nowtime – $lasttime`
echo -e "距离上次开盾已经:$gaptime S ,上次时间为:$lasttime"
fi
if [[ $cpu_load -gt $cpu_maxload ]]&&[[ $lasttime -eq "" ]]
then
echo "一分钟平均负载已超过阈值,开验证码"
curl -X PUT
-H "X-Auth-Email: $email"
-H "X-Auth-Key: $globalapi"
-H "Content-Type: application/json"
-d ‘{
"id": "$rulesid1",
"paused": false,
"description": "全部都验证码",
"action": "challenge",
"priority": 1000,
"filter": {
"id": "’$rulesid2’"
}
}’ "https://api.cloudflare.com/client/v4/zones/$zoneid/firewall/rules/$rulesid1"
rm -rf $cfile"xtime.txt"
lasttime=$(date +%s)
echo $lasttime >> $cfile"xtime.txt"
echo -e "n开验证码成功"
else
if [[ $cpu_load -lt $cpu_maxload ]]&&[[ $gaptime -ge $keeptime ]]
then
echo -e "n开盾时间已有$gaptime,超过$keeptime,且一分钟平均负载已低于阈值,尝试关盾"
curl -X PUT
-H "X-Auth-Email: $email"
-H "X-Auth-Key: $globalapi"
-H "Content-Type: application/json"
-d ‘{
"id": "$rulesid1",
"paused": true,
"description": "全部都验证码",
"action": "challenge",
"priority": 1000,
"filter": {
"id": "’$rulesid2’"
}
}’ "https://api.cloudflare.com/client/v4/zones/$zoneid/firewall/rules/$rulesid1"
rm -rf $cfile"xtime.txt"
else
if [[ $cpu_load -ge $cpu_maxload ]]&&[[ $gaptime -ge $keeptime ]]
then
echo -e "n开盾时间已有$gaptime,超过$keeptime,但是负载仍然较高暂不关验证码,请自行排查原因"
else
if [[ $lasttime -eq "" ]]
then
echo -e ""
else
echo -e "n开盾时间有$gaptime,未超过$keeptime,不关验证码或无需开验证码"
fi
fi
fi
@小小 大佬有话说 : 2020-1-2 08:29:13
:'(有大哥知道怎么回事吗
why? 大佬有话说 : 2020-1-2 09:51:02
bash -x 脚本,跑一下
@小小 大佬有话说 : 2020-1-2 10:03:29
本帖最后由 @小小 于 2020-1-2 10:06 编辑
好的
@小小 大佬有话说 : 2020-1-2 10:04:49
why? 大佬有话说 : 2020-1-2 09:51
bash -x 脚本,跑一下
有道http://note.youdao.com/noteshare?id=ba622b046d278261d77cd816787b61f2