I wrote the following script to kick out logged in users to Asterisk. (FreePBX deviceanduser mode)
#!/bin/sh DEVICES=`asterisk -rx "database show DEVICE" | grep -v "none" | grep "/user" | awk {'print $1'}` # Load text file lines into a bash array. OLD_IFS=$IFS IFS=$'\n' lines_ary=($DEVICES) IFS=$OLD_IFS # This will kick out all users logged into devices for idx in $(seq 0 $((${#lines_ary[@]} - 1))); do line="${lines_ary[$idx]}" #echo "TTT: ${line}" USER=`asterisk -rx "database show DEVICE" | grep $line | awk {'print $3'}` DEVICE=`echo $line | awk -F / '{ print $3 }'` #echo "ttT: $USER for $DEVICE" RES=`asterisk -rx "database put DEVICE/${DEVICE} user none"` echo $RES; echo "user $USER kicked out of device $DEVICE" done AMPUSERS=`asterisk -rx "database show AMPUSER" |grep device` # Load text file lines into a bash array. OLD_IFS=$IFS IFS=$'\n' lines_ary=($AMPUSERS) IFS=$OLD_IFS # This will remove all devices from AMPUSER/user/device for idx in $(seq 0 $((${#lines_ary[@]} - 1))); do #line="${lines_ary[$idx]}" line=` echo ${lines_ary[$idx]}| awk {'print $1'}` echo "TTT: ${line}" USER=`echo $line | awk -F / '{ print $3 }'` echo "ttT: $USER" DEVICE=` echo ${lines_ary[$idx]}| awk {'print $3'}` echo "dev: $DEVICE" RES=`asterisk -rx "database del AMPUSER/${USER} device"` echo $RES echo "device $DEVICE is removed from AMPUSER/$USER/device" done