Improved way of getting the next SIP extension
This commit is contained in:
parent
07b795222b
commit
7e59a41e4f
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue