#!/bin/bash
#定义一些变量
REDIS_HOST=192.168.10.38
REDIS_PORT=6370
REDIS_AUTH=123456
NGINX_BLOCKIPCONF_PATH=/data/software/openresty/nginx/conf.d/block_ip.conf
#接收需要查询的IP地址
echo -e "查询被www.baiinfo.com屏蔽的IP地址,请输入精确的IP地址 (支持格式: x.x.x. 或 x.x.x.x): "
read CHECK_IP
KEYS=$(echo "get website:incr$CHECK_IP")
DEL_KEYS=$(echo "del website:incr$CHECK_IP")
#判断lua的redis容器内IP是否存在,即已经拉入黑名单
RESULT=$(docker exec traffic_ip_redis redis-cli -p $REDIS_PORT -a $REDIS_AUTH --no-auth-warning $KEYS)
if [[ $RESULT -eq 1 ]]
then
echo -e "\n \033[31m 发现! \033[0m 您要查询的$CHECK_IP存在于traffic_ip_redis黑名单中."
echo -e "请确认是否删除? 确认输入(y),否则输入(n). "
read AGR_DEL
if [[ "$AGR_DEL" = "y" ]]
then
docker exec traffic_ip_redis redis-cli -p $REDIS_PORT -a $REDIS_AUTH --no-auth-warning $DEL_KEYS
echo -e "删除成功! \n"
else
echo -e "删除失败! \n"
fi
else
echo -e "\n 您要查询的$CHECK_IP不在traffic_ip_redis黑名单中."
fi
#判断nginx的.conf配置文件中IP是否存在,即已经拉入nginx拒绝访问IP名单中
RESULT2=$(cat $NGINX_BLOCKIPCONF_PATH | grep $CHECK_IP | wc -l)
if [[ $RESULT2 -eq 0 ]]
then
echo -e "\n 您要查询的$CHECK_IP不在nginx配置文件block_ip.conf的黑名单中."
else
echo -e "\n \033[31m 发现! \033[0m 您要查询的$CHECK_IP存在于nginx配置文件block_ip.conf的黑名单中."
echo -e "请确认是否删除? 确认输入(y), 否则输入(n). "
read AGR_DEL2
if [[ "$AGR_DEL2" = "y" ]]
then
sed -i "/$CHECK_IP/d" $NGINX_BLOCKIPCONF_PATH
echo -e "删除成功! 注意修改conf配置文件需要手动重新容器!"
else
echo -e "删除失败! \n"
fi
fi
标签:REDIS,shell,IP,redis,echo,nginx,conf,CHECK From: https://www.cnblogs.com/zhaolongisme/p/18053515