Count Extensions

From Pbxnsip Wiki

Jump to: navigation, search

Functionality

This script count how many extensions are in each domain. An example output looks like this:

abc.com 45
domain.com 43
tenant.com 21

You can easily change the script to show other account types as well.

Code

#!/bin/bash
# Show the passwords of all users:

function get_xml()
{
  gawk -v tag=$1 'BEGIN{regex="<" tag ">([^<]*)</" tag ">";}{ match($0, regex, m); for(i = 1;; i++) { if(!(i in m)) break; printf("%s\n"\
,m[i]);}}' $2
}

for dom in domains/*.xml; do
  name=${dom:8} # only the name
  idx=${name%.xml} # only the number
  dn=$(get_xml name $dom)
  if [ ! -z "$dn" ]; then
      count=0;
      for ext in users/*.xml; do
          domain=$(get_xml domain $ext)
          if [ "$domain" == "$idx" ]; then
              type=$(get_xml type $ext)
              if [ $type == "extensions" ]; then
                  count=$[$count+1]
              fi
          fi
      done
      echo $dn $count
  fi
done
Personal tools
Getting Help