#!/bin/bash # # leave_pin_conf.agi # # Find the desired ID in the pin conference database, # and decrement the number of conferees. # # Use the Linux "lockfile" command to control concurrent access # #set -x declare -a array while read -e ARG && [ "$ARG" ] ; do array=(` echo $ARG | sed -e 's/://'`) export ${array[0]}=${array[1]} done checkresults() { while read line do case ${line:0:4} in "200 " ) echo $line >&2 return;; "510 " ) echo $line >&2 return;; "520 " ) echo $line >&2 return;; * ) echo $line >&2;; #keep on reading those Invlid command #command syntax until "520 End ..." esac done } # Have conference IDs 101 - 106. Our "database" looks like this: # 101 0-N # 102 0-N # 103 0-N # . # . # 2nd column is number of people currently in the conference # We decrement the number by 1 DBFILE=/var/lib/asterisk/agi-bin/conf_id_db LOCKFILE=/tmp/conf_id_db.lock TMPFILE=/tmp/conf_id_db.tmp UPDATEID=$1 lockfile $LOCKFILE while read DBLINE do THISID=`echo $DBLINE | awk '{print $1}'` if [ $THISID = $UPDATEID ] then NUMCONFEREES=`echo $DBLINE | awk '{print $2}'` NEWNUMCONFEREES=`expr $NUMCONFEREES - 1` cat $DBFILE | sed -e "s/$UPDATEID $NUMCONFEREES/$UPDATEID $NEWNUMCONFEREES/" > $TMPFILE mv $TMPFILE $DBFILE fi done < $DBFILE rm -f $LOCKFILE exit 0;