#!/bin/bash
usersconf=/etc/asterisk/users.conf.test
password=admin
vendormac=00:0b
numdigs=2
secret=cnfywbz
num=1
cp ${usersconf} ${usersconf}.old
printf -v numt "%.*u" ${numdigs} ${num}
while read str ;
do
mac=$(echo -n ${str} | grep -o -E '([0-9a-z]{2}:){5}[0-9a-z]{2}' | grep "${vendormac}" | sed 's|:||g' )
if [ "${mac}" ] && [ ! "$(grep ${mac} ${usersconf})" ] ; then
ip=$(echo -n ${str} | grep -o -E '([0-9]{1,3}\.){3}[0-9a-z]{1,3}')
echo New phone found mac=${mac} ip=${ip}
while [ "$(grep "\[${numt}\]" ${usersconf} )" ] ;
do
echo Number ${numt} already exist. Skipping.
let num++
printf -v numt "%.*u" ${numdigs} ${num}
done
echo Assign to internal number ${numt}
( echo "[${numt}]"
echo macaddress = ${mac}
echo autoprov = yes
echo secret = ${secret}
echo fullname = ${numt}
echo ) >>${usersconf}
echo Reload asterisk config
# asterisk -rx "config reload ${usersconf}"
echo Reboot phone
# gsreboot ${password} ${ip}
let num++
printf -v numt "%.*u" ${numdigs} ${num}
echo ---
fi
done
↧
Script to search for new handsets and automatically fill users.conf
↧