Conditional Blacklist?

Ahh, I see the issue, it has a trailing new line.

Try this:

#!/bin/bash

phone_number="$1"

if [ -z "$phone_number" ]; then
    echo "Usage: $0 <phone_number>"
    exit 1
fi

# Increment the counter for the phone number
value=$(/usr/bin/redis-cli INCR "$phone_number")

# Set/refresh expiration to 300 seconds
/usr/bin/redis-cli EXPIRE "$phone_number" 300 >/dev/null

# Uncomment the following to log and troubleshoot
echo "$phone_number $value" >> /home/asterisk/CustomScripts/busylog.txt

# Check rate and print action
if [ "$value" -ge 5 ]; then
    echo -n "block"
else
    echo -n "continue"
fi
1 Like