In Loki We Trust The many projects of Lokkju, Inc

participate
13Apr/060

Bash/perl command to get all asterisk functions

I needed a lits of all the asterisk functions, in a html list format, so I whipped up this:

sudo -u www-data asterisk -rx 'show functions'|grep \(|awk '{print $1}'|while read line; do sudo -u www-data asterisk -r -n -q -x 'show function '$line''|perl -0777 -ne "\$f = \$_;\$f = s/\033\[(?:\d+(?:;\d+)*)*m//go;if (/function\s'(.*?)'.*?\[Syntax\]\n(.*?)\n.*?\[Synopsis\]\n(.*?)\n.*?\[Description\]\n(.*?)\n/sg) {print '<li>' . \$1 . '<span class="informal"><span class="syntax">' . \$2 . '</span><span class="synopsis">' . \$3 . '</span><span class="description">' . \$4 . '</span></span></li>' . \"\\n\";}" ; done

and for all applications, xml format:

sudo -u www-data asterisk -rx 'show applications'|grep :| awk -F : '{gsub( /^ +| +$/, "", $1 ) ; print $1}'|sort|while read line; do sudo -u www-data asterisk -r -n -q -x 'show application '$line''|perl -0777 -ne "\$f = \$_;\$f = s/\033\[(?:\d+(?:;\d+)*)*m//go;\$f = s/\</&lt;/go;\$f = s/\>/&gt;/go;if (/application\s'(.*?)'.*?\[Synopsis\]\n(.*?)\n.*?\[Description\]\n(.*?)\n(.*?)\n\n/sg) {print '<application><name>' . \$1 . '</name><synopsis>' . \$2 . '</synopsis><usage>' . \$3 . '</usage><description>' . \$4 . '</description></application>' . \"\\n\";}"  ; done

Obviously, replace the www-data username with your asterisk username. Also, if you want to change the output details, just change the last bit, where perl outputs the results of the regex.

Have fun.

careers
Filed under: Projects No Comments
tools
   
content
address