可以将xargs替换为while循环以避免argument line too long错误。具体修改后的脚本如下:#!binbashcheck_results=redis-cli -c -h $1 -p $2 -a $3 EOFsentinel mastersexitEOFmaster_name=echo $check
可以将代码最后的for循环部分修改为while循环,如下所示:
#!/bin/bash
check_results=redis-cli -c -h $1 -p $2 -a $3 <<EOF sentinel masters exit EOF
master_name=echo $check_results | sed -e 's/ip[[:space:]].*//g' -e 's/name//g' -e 's/[[:space:]]//g'
master_ip_port=redis-cli -c -h $1 -p $2 -a $3 <<EOF sentinel GET-MASTER-ADDR-BY-NAME $master_name exit EOF
master_ip=echo $master_ip_port|sed -e 's/[[:space:]].*//g'
master_port=echo $master_ip_port|sed -e 's/.*[[:space:]]//g'
master_password=$4
OLD_IFS="$IFS"
IFS=" "
key_list=(${@:5})
IFS=$OLD_IFS
echo $key_list
total_deleted=0
for key in ${key_list[@]}
do
echo $key
redis-cli -c -h $master_ip -a $master_password -p $master_port --scan --pattern $key | while read redis_key; do
result=redis-cli -c -h $master_ip -a $master_password -p $master_port del $redis_key
echo $result
((total_deleted+=result))
done
done
echo "Total number of keys deleted: $total_deleted
原文地址: http://www.cveoy.top/t/topic/hr7n 著作权归作者所有。请勿转载和采集!