#!/bin/sh                                                                                                                                                                                                                                 
  1                                                                                                                                                                                                                                           
  2 HOST="redis-cache-master"                                                                                                                                                                                                                 
  3 PORT="6379"                                                                                                                                                                                                                               
  4 PATTERN="nginx-cache:*"                                                                                                                                                                                                                   
  5                                                                                                                                                                                                                                           
  6 echo "redis.clear.cache:start"                                                                                                                                                                                                            
  7                                                                                                                                                                                                                                           
  8 CURSOR=0                                                                                                                                                                                                                                  
  9 while true; do                                                                                                                                                                                                                            
 10 │ SCAN_RESULT=$(echo -e "SCAN $CURSOR MATCH $PATTERN COUNT 100\r\n" | nc $HOST $PORT)                                                                                                                                                     
 11 │ CURSOR=$(echo "$SCAN_RESULT" | sed -n '3p')                                                                                                                                                                                             
 12 │ KEYS=$(echo "$SCAN_RESULT" | sed -n '5,$p' | awk 'NR % 2 == 0')                                                                                                                                                                         
 13 │                                                                                                                                                                                                                                         
 14 │ for KEY in $KEYS; do                                                                                                                                                                                                                    
 15 │ │ if [ -n "$KEY" ]; then                                                                                                                                                                                                                
 16 │ │ │ echo "Deleting key: $KEY"                                                                                                                                                                                                           
 17 │ │ │ echo -e "DEL $KEY\r\n" | nc $HOST $PORT > /dev/null                                                                                                                                                                                 
 18 │ │ fi                                                                                                                                                                                                                                    
 19 │ done                                                                                                                                                                                                                                    
 20 │                                                                                                                                                                                                                                         
 21 │ if [ "$CURSOR" = "0" ]; then                                                                                                                                                                                                            
 22 │ │ break                                                                                                                                                                                                                                 
 23 │ fi                                                                                                                                                                                                                                      
 24 done                                                                                                                                                                                                                                      
 25                                                                                                                                                                                                                                           
 26 echo "redis.clear.cache:done"  

what is wrong with this script? it is endlessly running, could you fix it?