Improved way of getting the next SIP extension

This commit is contained in:
Bob Mottram 2015-11-02 15:30:24 +00:00
parent 07b795222b
commit 7e59a41e4f
1 changed files with 6 additions and 21 deletions

View File

@ -31,27 +31,12 @@
CONFIG_FILE=/etc/sipwitch.conf
extensions=()
# get the used extensions
IFS=''
for line in $(cat $CONFIG_FILE | grep "extension"); do
extnum=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
extensions+=($extnum)
done
# find the max extension number
maxnum=201
for i in ${extensions[@]}; do
if [ $i -gt $maxnum ]; then
maxnum=$i
break
fi
while (( maxnum < 299 )); do
if ! grep -q "extension>$maxnum<" $CONFIG_FILE; then
break;
fi
maxnum=$((maxnum + 1))
done
if [ $maxnum -gt 299 ]; then
exit 1
fi
echo $(($maxnum + 1))
echo $maxnum
exit 0