The site that caused me to set up bell paging on our trixbox system also threw me a curveball by having an "alternate" schedule that they needed implemented every Thursday, although occasionally they need to set the "Thursday" schedule on other days of the week. I got tired of manually updating the crontab for these times, so I configured a feature code so that they could override the normally programmed time themselves.
First create a custom context to use as a destination that will run the script that modifies our crontab
edit /etc/asterisk/extensions_custom.conf ad add something like
[ext-belltoggle-custom]
exten => s,1,AGI(toggle-bells.sh)
Next create a custom destination to trigger that context
Custom destination : ext-belltoggle-custom,s,1
Description: Toggle Bells
Then create a Misc Application to trigger our custom destination:
Description: Toggle Bells
Feature Code: *281 (or whatever you like)
Feature Status: Enabled
Destination: Custom Destinations -> Toggle Bells
Create toggle-bells.sh in /var/lib/asterisk/agi-bin with the following
#!/bin/bash
# Consume all variables sent by Asterisk
while read VAR && [ -n ${VAR} ] ; do : ; done
# Answer the call.
echo "ANSWER"
read RESPONSE
# Say the letters of "Hello World"
#echo 'SAY ALPHA "Hello World" ""'
#read RESPONSE
if crontab -l | grep -q "ALTERNATE"; then
echo "51 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php
1 00 * * 1,2,3,5 /usr/bin/crontab /var/lib/asterisk/scripts/normalbells
1 00 * * 4 /usr/bin/crontab /var/lib/asterisk/scripts/alternatebells
1 00 * * 0,6 /usr/bin/crontab /var/lib/asterisk/scripts/weekendbells
##NORMAL BELLS##
##Put your normal schedule here with lines like the following##
30 08 * * * /usr/sbin/asterisk -rx 'originate Local/8102@ext-paging extension 8103@ext-paging'
" | crontab -
echo 'EXEC PLAYBACK "custom/NormalBellActivated" ""'
read RESPONSE
elif crontab -l | grep -q "NORMAL"; then
echo "51 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php
1 00 * * 1,2,3,5 /usr/bin/crontab /var/lib/asterisk/scripts/normalbells
1 00 * * 4 /usr/bin/crontab /var/lib/asterisk/scripts/alternatebells
1 00 * * 0,6 /usr/bin/crontab /var/lib/asterisk/scripts/weekendbells
##ALTERNATE BELLS##
##Put your alternate schedule here with lines like the following##
35 08 * * * /usr/sbin/asterisk -rx 'originate Local/8102@ext-paging extension 8103@ext-paging'
" | crontab -
echo 'EXEC PLAYBACK "custom/AlternateBellActivated" ""'
read RESPONSE
fi
exit 0
Create 3 crontab files in /var/lib/asterisk/scripts/ called normalbells alternatebells and weekendbells that will be sourced to set the schedule to the normal time each day.
They should look identical to what the asterisk user's crontab looks like when it's in one of the modes.
Finally, create two system recordings named NormalBellActivated and AlternateBellActivated that will be used to inform the user which mode they're in.
No comments:
Post a Comment