Companylist

I want a sctpit to open /etc/asterisk/sip_conf

and between [XXXXX] and [XXXX] finds callerID=NAME ,Extension number
then write is in a file in a CSV format named /tftpbot/companylist.csv with formaon NAME, EXTENSION,

and this script should be rerun each time the system is reloaded. How can I do this?

I can be the only person that wants list. Who know what for?

Reports-> print extensions

I guess one of us is missing something. I would like FREEPBX to rewrite a file named /tftpbot/companylist.csv each time the system is reloaded. The data needed comes from /etc/asterisk/sip_conf

Reports -> print extensions only shows you a page of extension and some of the dial plan.

This for Aatra/Mitel users.

That will be very hard to do as most Freepbx based systems will not have a file called /etc/asterisk/sip_conf

But if you want to use the /etc/asterisk/sip*.conf files then maybe

cat /etc/asterisk/sip*.conf|grep callerid|cut -d “=” -f2|rev|awk ‘{print $1,$2,$3,$4}’|grep ‘<’|sed -e ‘s/>/"/’ -e ‘s/< /","/’ -e ‘s/\s*$/"/’|rev|sed ‘s/"+/"/g’

might get you close.

But I should point out that there would be a more elegant solutions using sqlite3 and the asterisk database, just trigger your script with an incron entry whenever the database changes.

/usr/bin/sqlite3 /var/lib/asterisk/astdb.sqlite3 ‘SELECT ltrim(rtrim(key,"/cidname"),"/AMPUSER"),value from astdb WHERE key BETWEEN “/AMPUSER/XXXX” AND “/AMPUSER/XXXXX” AND key LIKE “%CIDNAME%”’|awk -F “|” ‘{print “”"$2"",""$1"""}’> /tftpbot/companylist.csv

Notice XXXXX must be larger that XXXX ,and you will have to change your tftpserver to use /tftpbot instead of the preferred /tftpboot to do it your way

1 Like

A couple of things.

  1. Most of the dynamic configuration files including the SIP configurations are generated from a database. This means you can programmatically pull what info you need.

  2. This is open source software so you can look at how the aforementioned module does what it does. This may help you in accomplishing your desired goal

  3. The Wiki has a section called the Developers Corner which may be helpful to you to…

  • Learn how to develop stuff that interacts with FreePBX
  • Learn how to hook in to things so your stuff runs during things like regenerating configs.

@Dicko’s answer should give you a starting point if you insist on playing with configuration files to get the information you desire. I personally think it better to pull it from the “horses mouth”

Just to add to James’ comments, my second post does indeed pull the data from the “horses mouth” bypassing FreePBX completely, it’s just core Asterisk and how it currently stores that data (obviously derived from the FreePBX GUI) plus a modicum of SQL query language to translate what you asked for into how it can be done very simply in one line of code.

@dicko I hadn;t looked at your second answer.
Generating a file whenever astdb changes could get very heavy as it changes very frequently for various reasons. I have very limited interactions with sqlite. I know you can register a hook in to it but you would have to lock your trigger to certain keys if that is possible.

On a side note it would be cool to see how many times it would trigger on an active system.

I spoke too quickly :wink: he should probably trigger the incron on changes to /etc/asterisk/* which is far less mutable, I think sqlite3 probably commits to disk every minute by default in asterisk.

I didn’t have any infomation in my old *box but on new beta distro astdb.sqlite2 had the information. I changed /tftpbot/companylist.csv to /tftpboot/
I tried it and it only emptied the file, didn’t add the data. I think its writing to the correct file or it would have not deleted the test text a add to the companylist.csv file.

My the way, Dicko. Thank you for taking the time to respond my questions

If you are using Asterisk later than three years old then the default database will be:-

/var/lib/asterisk/astdb.sqlite3

you have to be specific. Until you get something back from :-

sqlite3 /var/lib/asterisk/astdb.sqlite3 ‘SELECT * from astdb’

then you can’t go further.

Are you sure you are ready for using a Beta distribution? it demands a certain amount of ability, and a certain attention to detail you have yet to show :slight_smile:

James, Without being nit-picky it is sqlite3 (case sensitive, much as linux and my username is :slight_smile: )and is the engine that Asterisk drives it’s database with now unless as posi211 infers the beta has reverted back to sqlite (which is probably sqlite2 but probably known as sqlite on many systems that have been around for a while).

I’m using version 6.12.65-13
And when I look at the sqlite3 it has some clear text with the extension number but not the display name.

I like the sip_additional.conf file as it looks easier to me to pick out the data

so
cat /etc/asterisk/sip_additional.conf\grep callerid|cut HELP…

This script would only need to be run when an extension change was added or changed. I’m using it to load into the Aastra/Mitel phones for the directory.

Well that is probably not your best move, from:-

http://wiki.freepbx.org/display/FD/FreePBX-Distro-6.12.65

Which specifically states

“FreePBX Distro 6.12.65-13 Skipped due to internal screwup” and the always good advice that you should NEVER use beta software in a production environment especially a broken/skipped one, I guess you have your reasons though, good luck otherwise . . .

1 Like

Thanks for the info. its on a sandbox just looking at the new design. I like it. Will this track get dropped for a stable version or patched to a long term version?

If the new dashboard in the non beta?

That would surely be a question to ask in the more appropriate “Beta Program Issues” forum.

cat /etc/asterisk/sip*.conf|grep callerid|cut -d “=” -f2|rev|awk ‘{print $1,$2,$3,$4}’|grep ‘<’|sed -e ‘s/>/"/’ -e ‘s/< /","/’ -e ‘s/\s*$/"/’|rev|sed ‘s/"+/"/g’

And it printed on the screen the data. I just need to write it to the file.

When I try
/usr/bin/sqlite3 /var/lib/asterisk/astdb.sqlite3 ‘SELECT ltrim(rtrim(key,"/cidname"),"/AMPUSER"),value from astdb WHERE key BETWEEN “/AMPUSER/XXXX” AND “/AMPUSER/XXXXX” AND key LIKE “%CIDNAME%”’|awk -F “|” ‘{print “”"$2"",""$1"""}’> /tftpbot/companylist.csv
I get and error -bash: /tftpbot/companylist.csv: No such file or directory
But I want the file in tftpboot/companylist.csv
So I changed tftobt to tftpboot with same error.

can’t I just get this output to a file?

Of course, but you will need to know how, I would google “bash tutorials” and spend a few hours there to your ongoing benefit with all things linux. I would also caution you to slow down. smell the roses, and be precise, your posts are scattered with typos and incorrectnesses (that word itself horribly incorrect :slight_smile: ) and I admit to teasing you indirectly from my first post onwards :wink: , you will NEED to be correct in everything you do (and type) if you want it to work.

Ok I will relent a little, you state

I get and error -bash: /tftpbot/companylist.csv: No such file or directory
But I want the file in tftpboot/companylist.csv
So I changed tftobt to tftpboot with same error.strong text

now in general the directory /tftpbot will not exist, /tftpboot however probably does, but tftboot/ is relative to wherever your script is at , you missed the initial / which will “root” it, then you continue with your ADHD behavior by stating “tftobt to tftpboot” do you see why you need to be a little more careful? To experiment, just leave out the redirection into a file bit “>” and watch what happens on your screen (which in linux is the default output file /dev/stdout, you will read about that in the tutorials if you care to go there)

dicko sure knows how to put the dick in the “o” doesn’t he?

Anyway…I think he is right, you had a typo cuz >> appends and > writes stdout to a file

This hasne’t changes since I used system V in college 34 years ago. (I have outlived my usefulness, being clever in forums is all I have to cling to)

Can you imagine dicko and i chasing each other down the hall in the nursing home, oh noooooo