Scheduling Calls in the Future

There are 3 ways (that i know of) to schedule a future outbound call in Asterisk.

  1. Set the date on a call file to a point in the future.
  2. Use CRON to periodically query a Database to determine whether call files should be generated.
  3. Use Asterisk’s calendar functionality to set an event which triggers the call.

I will ignore “3” for now, since I’ve never used this relatively new functionality, and from what I’ve seen, it’s more complicated than what most people need.  So let’s look at the first two.

Setting the date on a call file:  As you know by now, Asterisk will immediately make an outbound call once a call file is moved into /var/spool/asterisk/outgoing.  However, the whole truth is actually more subtle and interesting.  Asterisk will only execute the call file if the file’s date is in the past.  If the date is in the future, then Asterisk will wait until that date has passed, and will then make the call.  If you want a call to happen at a certain time, then simply change the call file’s date to that time, and move it to /var/spool/asterisk/outgoing.

You can change a file’s date on the command line by using the “touch” command, which is built into all UNIX style OS’s, including Linux and OSX.  Using the “-t” option, you can set the time with the format (Y-Year, M-Month, D-Day, h-hour(24 hour time), m-minute, s-second).

touch -t somefile.txt

The following example will change the date of file “” to April 1, 2013, 1:00pm (13:00).

touch -t 201304011300.00

Ruby’s File class has a method called “utime” that can also change the date on a file.

#set time to call for April 1, 1:00pm (13:00).
File.utime(time_to_call, time_to_call, callfile)

Ruby’s Time class allows for basic arithmetic, which makes it easy to set calls in “an hour from now” or “in two days from now”.

#set time to call in one hour.
callfile="/home/ck987/" with no arguments will set to current time
#add enough seconds to equal 1 hour (60 seconds in 1 minute, 60 minutes in an hour)
time_to_call += (60*60)
File.utime(time_to_call, time_to_call, callfile)