I’ve started to cobble together some bash functions to help with common Asterisk administration tasks. Here is a useful snippet for getting free sip users from your sip.conf. If you are on a CentOS box you can put this in /etc/profile.d/asterisk.sh to make it available to everyone on the system.
# Free SIP extensions
# Usage: freesip /etc/asterisk/sip.conf 200 299
freesip() {
comm -2 <(seq $2 $3) <(cat $1 | grep ^\[ | sort | uniq | tr -d [ | tr -d ]) | grep ^[[:digit:]]
}
$ freesip /etc/asterisk/sip.conf 200 299 200 201 233 245 $