Listing 1 - Example Callerid AGI Script
---------------------------------------


#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}

set port 10000
set hosts [list 192.168.123.166 192.168.123.168]

##
##  Sends the info to the hosts
##
proc sendInfo {ip_ port_ callerid_} {

  if {[catch {socket $ip_ $port_} sock]} {
    return
  }

  fconfigure $sock -buffering line
  puts $sock $callerid_
  close $sock

  return
}

##
##  We get all of the variables from stdin;
##  they start with "agi_"; and populate
##  an array with the values.
##
while {[gets stdin l] > 0} {
  if {[regexp {^agi_([\w]+):[\s]+(.*)} $l -> k v]} {
    set AGI($k) $v
  }
}

##
##	Send the callerid info to each host
##	that we have listed
##
foreach H $hosts {
  sendInfo $H $port $AGI(callerid)
}