while read channel qidletime; dodevice=`asterisk -rx "database showkey AMPUSER/${channel:6}/device" | grep -a device | cut -d":" -f2 | sed 's/ //g' `dial=`asterisk -rx "database showkey DEVICE/$device/dial" | grep -a dial | cut -d":" -f2 | sed 's/ //g' `lastactivity=`asterisk -rx "database showkey AMPUSER/${channel:6}/lastactivity" | grep -a ${channel:6} | cut -d":" -f2 | sed 's/ //g' `time=`date +%s`echo $timeecho $lastactivityecho $maxtime # Member didnt recive a q call in the past maxtime, check the lastactivity and log him off if (( ${qidletime} >= ${maxtime} )); then if (( $(($time - $lastactivity)) >= $maxtime )); then logoff $channel $device; fi fi # Member didnt make a call in the past maxtime, check the qidletime and log him off if (( $(($time - $lastactivity)) >= $maxtime )); then if (( ${qidletime} >= ${maxtime} )); then logoff $channel $device; fi fi #Member hasnt recived ANY q calls (so he has no qidletime), just check lastactivity and log him off if (( -z ${qidletime} )); then if (( $(($time - $lastactivity)) >= $maxtime )); then logoff $channel $device; fi fidone <<< "$qmembers"