Out of curiosity: Whats the reason you want to route after hours calls to that queue but you want the queue to be empty, why not just route the after hours calls to the failover destination?
If for some reason you do want the calls to go to that queue, maybe a cronjob that logs them out instead of sending an email would work?
If you do want to send an email instead of logging them out, it’s doable.
We recently had the opposite request, a critical queue which is required to be staffed 24/7, and if the queue is empty they wanted an email alert. So instead of having a process running or a crontab every couple of minutes, In the Agent Logoff context and as well as the incoming calls context we had a single line and it works fine so far.
exten => s,n,ExecIf($["${QUEUE_MEMBER(QueueNum,logged)}" = "0"]?System(echo "Queue is empty" | mail -s "This is the subject" [email protected]))
So normally, as soon as the last agent logged of it would trigger this email, but if for some reason the last agent was removed from the queue via CLI or a different way, then an email would be sent as soon as the next caller hits the Trunk.
You can do the opposite:
exten => s,n,ExecIf($["${QUEUE_MEMBER(QueueNum,logged)}" != "0"]?System(echo "Members in queue: ${QUEUE_MEMBER_LIST(QueueNum)}" | mail -s "This is the subject" [email protected]))
However, if you want to run this with a bash script and a cronjob, you can run something like:
/usr/sbin/asterisk -x"database showkey Queue/PersistentMembers/QueueNum"
If no one is logged in, it should return:
0 results found.
If someone or more than one logged in, it should return: (in the example here two agents are logged in)
/Queue/PersistentMembers/QueueNum : Local/204@from-queue/n;0;0;Jean;hint:204@ext-local|Local/202@from-queue/n;0;0;Mike;hint:202@ext-local
1 results found.
So write your script to send an email based on the result it returns.
Hope that helps.