#!/bin/bash ####### Asterisk Telephony Server if [ -a /usr/sbin/asterisk ] then ASTBIN=/usr/sbin/asterisk else ASTBIN=$(which asterisk) fi if [ "$ASTBIN" != "" ] then echo '<<>>' astcmd () { #asterisk -rx "$1" | grep -v "Asterisk ending" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' $ASTBIN -rx "$1" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' } #CORECHANNELS=$(astcmd 'core show channels' | tail -3) CORECHANNELS=$($ASTBIN -rx 'core show channels' | tail -3) ACTIVECHAN=$(echo "$CORECHANNELS" | grep -o '[0-9]* active channel' | cut -d' ' -f1) ACTIVECALL=$(echo "$CORECHANNELS" | grep -o '[0-9]* active call' | cut -d' ' -f1) IAXCHANNELS=$(astcmd 'iax2 show channels' | tail -1 | cut -d' ' -f1) SIPCHANNELS=$(astcmd 'sip show channels' | tail -1 | cut -d' ' -f1) SIPPEERS=$(astcmd 'sip show peers' | tail -1) SIPTOTALPEERS=$(echo "$SIPPEERS" | cut -d' ' -f1) SIPONLINE=$(echo "$SIPPEERS" | grep -o '[0-9]* online' | head -1 | cut -d' ' -f1) IAXPEERS=$(astcmd 'iax2 show peers' | tail -1) IAXTOTALPEERS=$(echo "$IAXPEERS" | cut -d' ' -f1) IAXONLINE=$(echo "$IAXPEERS" | grep -o '[0-9]* online' | head -1 | cut -d' ' -f1) PJSIPCHANNELS=$($ASTBIN -rx 'pjsip show channels' | grep -c "Channel: PJSIP") PJSIPONLINE=$($ASTBIN -rx 'pjsip show endpoints' | grep 'Contact: ' | grep -c -v '