Quantcast
Channel: VOIP-info.org Page Changes
Viewing all articles
Browse latest Browse all 2667

Script to search for new handsets and automatically fill users.conf

$
0
0
Diff from version 2 to 10 (current)

@@ -1 +1,42 @@

-{attachment id=4652}
+cat addphone.sh
+~pp~
+#!/bin/bash
+usersconf=/etc/asterisk/users.conf # Asterisk users.conf file
+password=admin # Phone admin password for remote reboot
+vendormac=00:0b # Vendor mac address prefix (00:0b - Grandstream)
+numdigs=2 # Number of digits in internal phone numbers 2 - 00 3 - 000 4 - 0000
+secret=cnfywbz # sip password
+num=1 # start phone number
+
+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}" # Informs asterisk that changed config file
+ echo Reboot phone
+ gsreboot ${password} ${ip} # Remote reboot phone for autoprovisioning
+ let num++
+ printf -v numt "%.*u" ${numdigs} ${num}
+ echo ---
+fi
+done
+~/pp~
+{attachment id=4653}
UserCommentTimeVersion
laigor2014-03-27 20:3210
laigor2014-03-27 20:319
laigor2014-03-27 20:308
laigor2014-03-27 20:296
laigor2014-03-27 20:285
laigor2014-03-27 20:274
laigor2014-03-27 20:153
laigor2014-03-27 20:102

Viewing all articles
Browse latest Browse all 2667

Trending Articles