I wanted to make my slug running Asterisk do wakeup calls, since I currently pay $11/month for a daily wakeup call service and they’ll only try up to 4 times. As my starting point, I was using this dialplan from the-asterisk-book.com:
-
[hotel-intern]
-
exten => _*77*XXXXXXXXXXXX,1,Answer()
-
exten => _*77*XXXXXXXXXXXX,n,Set(year=${EXTEN:4:4})
-
exten => _*77*XXXXXXXXXXXX,n,Set(month=${EXTEN:8:2})
-
exten => _*77*XXXXXXXXXXXX,n,Set(day=${EXTEN:10:2})
-
exten => _*77*XXXXXXXXXXXX,n,Set(hours=${EXTEN:12:2})
-
exten => _*77*XXXXXXXXXXXX,n,Set(minutes=${EXTEN:14:2})
-
exten => _*77*XXXXXXXXXXXX,n,NoOp(Wake-up call scheduled for ${CALLERID(num)} at ${hours}:${minutes} on ${day}.${month}.${year}.)
-
exten => _*77*XXXXXXXXXXXX,n,System(echo -e "Channel: SIP/${CALLERID(num)}\\nContext: wake-up\\nExtension: 23" > /tmp/${UNIQUEID}.call)
-
exten => _*77*XXXXXXXXXXXX,n,System(touch -t ${year}${month}${day}${hours}${minutes} /tmp/${UNIQUEID}.call)
-
exten => _*77*XXXXXXXXXXXX,n,System(mv /tmp/${UNIQUEID}.call /var/spool/asterisk/outgoing/)
-
exten => _*77*XXXXXXXXXXXX,n,Playback(rqsted-wakeup-for)
-
exten => _*77*XXXXXXXXXXXX,n,SayNumber(${hours})
-
exten => _*77*XXXXXXXXXXXX,n,SayNumber(${minutes})
-
exten => _*77*XXXXXXXXXXXX,n,Hangup()
-
-
[wake-up]
-
exten => 23,1,Answer()
-
exten => 23,n,Wait(1)
-
exten => 23,n,Playback(this-is-yr-wakeup-call)
-
exten => 23,n,Wait(1)
-
exten => 23,n,Hangup()
The problem is that my slug is unslung, running busybox for most basic *nix tools and busybox’s touch command doesn’t support the -t option, so I can’t set the modification time on the file to properly queue it. My half-assed workaround is a shell script (because I couldn’t get the System() command to run the whole string, try as I might) that nohups a background shell process that sleeps for the difference in seconds between now and the wakeup time, then creates the call file. Not great for far-future scheduling or for large numbers of calls and it won’t survive a reboot, but it’s a start.
-
-
nohup sh -c "sleep $((`/bin/date –date="$1" +"%s"` – `/bin/date +"%s"`)) ; echo -e 'Channel: $2\\nContext: wake-up\\nExtension: 23' > /tmp/$3.call ; mv /tmp/$3.call /opt/var/spool/asterisk/outgoing/" >/dev/null &
My Asterisk diaplan macro passes the target time/date string as the first argument, the target channel as the second, and the ${UNIQUEID} as the third. One further wrinkle: busybox 1.3.1, which was what came with the unslung firmware I used, doesn’t have nohup, so it won’t work; busybox 1.10.3 is what ipkg installed into /opt/ and has nohup, but the date command in 1.10.3 didn’t seem to support –date (at all, or maybe just not properly), so nohup is a reference to the 1.10.3 busybox in /opt/bin while /bin/date is a reference to the original 1.3.1 busybox. Stupid, but it works.
(Oh, and as I told the last person I saw wearing a t-shirt that said “If it’s stupid, but it works, then it isn’t stupid,” there’s definitely such a thing as works-but-stupid–this script hackery is such a thing. The better solution, space permitting, is probably just to install the coreutils package so as to have proper non-busybox touch and date)