First, modify the script to the correct quotes and echo the data into the log file before the if statement
#!/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 "block"
else
echo "continue"
fi
Then, update the dialplan so you can see what it returns
[time-based-block]
exten => s,1,Noop(Check if we need to prevent ${CALLERID(all)} from reaching the queue)
same => n,Set(callAmount=${SHELL(/home/asterisk/CustomScripts/busytimescript.sh ${CALLERID(num)})})
same => n,GotoIf($["${callAmount}"="block"]?block)
same => n,Return()
same => n(block),Goto(ivr-15,s,1)
We are getting there. Here’s the call trace after the last change:
I did try switching the last two lines of the dialplan around so it hits the block before the return. That directed all of the calls to the blocked IVR.
If I’m reading the trace right, somewhere in the area of line 81, it looks like the GOTO line is not “GOTOing.” Is there an extra $ in the line?
#!/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
Thank you very much! Not only have you showed me a powerful way to customize FreePBX, the system works as it was designed… and my team is much happier!
For those looking for the solution - I marked the last iteration of the script - but it also needs the dialplan.
Here is the script I used:
Hello! and thank you for calling (…). We are open and our phones are working. We’ve noticed several calls from this number in a short period of time. We’re currently helping other clients and want to make sure everyone receives the attention they deserve. We appreciate your patience and understanding.
To leave a message for a prescription refill, please press 1
To leave a general message about an appointment or to request a callback, please press 2
To leave a message about an emergency, please press 3 and follow the instructions provided.