BASH script to logout Dynamic Agents
This is a simple script for logging out Dynamic Agents in Asterisk. The most common use would be to logout Agents automatically each day in case they forget or are on PAUSE. Edit the “LOGGEDIN” variable below to match the correct length of digits. By default it is three, ‘SIP/…’.
You can add as many or as few Queues in place of QUEUE1, QUEUE2, & QUEUE3. This is the ‘foreach’ section of the script. Whatever that is here will be applied to each instance of SIP/xxx detected by grep. Good luck.
agent-auto-loggoff.script
————————————————————————–
#!/bin/bash
#set -x
# Execute from the command line, Asterisk or by cron
LOGGEDIN=$(/usr/sbin/asterisk -rx “queue show” | /bin/grep -o ‘SIP/…’)
for i in $LOGGEDIN
do
echo “$i removed”
# Add in all queues that should be included
#==============
/usr/sbin/asterisk -rx “queue remove member $i from QUEUE1”
/usr/sbin/asterisk -rx “queue remove member $i from QUEUE2”
/usr/sbin/asterisk -rx “queue remove member $i from QUEUE3”
done
exit
2 Comments »
RSS feed for comments on this post. TrackBack URL
#!/bin/sh
# Begin /etc/init.d/reboot
#
# Call reboot. See man halt for the meaning of the parameters
#
echo “starting script” > rebootLogFile
for queue in
rasterisk -rx "queue show" | grep strategy | awk '{print $1}'
do
echo “$queue found” >> rebootLogFile
for agent in
rasterisk -rx "queue show $queue" | grep Local/ | awk '{print $2}'
do
agent=$(echo $agent | sed -e ‘s/(//g’)
agent=$(echo $agent | sed -e ‘s/)//g’)
agentNumber=$(echo $agent | sed -e ‘s/Local\///g’)
agentNumber=$(echo $agentNumber | sed -e ‘s/@from-queue\/n//g’)
echo “$agent found” >> rebootLogFile
asterisk -rx “queue unpause member $agent queue $queue reason ‘none'”
echo “$agent unpause member” >> rebootLogFile
asterisk -rx “database put AMPUSER $agent/pauses 0”
echo “$agent change database user state.” >> rebootLogFile
asterisk -rx “queue remove member $agent from $queue”
echo “$agent unpaused and logged out” >> rebootLogFile
asterisk -rx “devstate change CUSTOM:PAUSE$agentNumber NOT_INUSE”
echo “$agentNumber paused devstate changed” >> rebootLogFile
asterisk -rx “devstate change Custom:QUEUE$agentNumber*$queue NOT_INUSE”
echo “$agentNumber logged out devstate changed” >> rebootLogFile
done
done
/sbin/reboot -d -f -i
# End /etc/init.d/reboot
EOF
What’s this script for?