AppleScript C Perl Shell Xcode Other

Updating asterisk phonebook database VIA ssh unattended

Post Reply
coding / shell     Views: 841Prev .. Next
Updating asterisk phonebook database VIA ssh unattendedPosted: Thursday, October 12, 2017 [07:54:32] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
If you run contact database on a server other than asterisk server (FreePBX or any other) and want to update Asterisk Phonebook which could be used as CID lookup source.
Asterisk uses the following commands:
View CodeCLI> help database
database del - Removes database key/value
database deltree - Removes database keytree/values
database get - Gets database value
database put - Adds/updates database value
database show - Shows database contents
database show key - Shows database contents


Add database value:
View CodeCLI> database put cidname 12345678 "Asterisk"
Updated database successfully


Retrieve data:
View CodeCLI> database get cidname 12345678
Value: Asterisk


Delete data:
View CodeCLI> database del cidname 12345678
Database entry removed.


If you want to remove the entire family of cidname values:
View CodeCLI> database deltree cidname
Database entries removed.


If you want to see all the values for a particular family, you can use the command “database show” like this:
View CodeCLI> database show cidname
/cidname/12345678 : Asterisk


If using SSH with auto login - string should be:
View Codessh root@IP_ADDRESS 'asterisk -rx \'database del cidname NXXXXXXXXX\''
or
ssh root@IP_ADDRESS 'asterisk -rx \'database put cidname NXXXXXXXXX "Contact Name"\''

but it won't work as escaping single quotes(') will 'couse CLI to fail.

What works is a cron job or any other daemon to run SSH command.
A here-doc with quoted delimiter works great:
View Codessh -T root@IP_ADDRESS <<'EOF'
asterisk -rx 'database del cidname NXXXXXXXXX'
EOF

or
View Codessh -T root@IP_ADDRESS <<'EOF'
asterisk -rx 'database put cidname NXXXXXXXXX "Contact Name"'
EOF

the -T option prevents ssh complaining about not allocating a pseudo-terminal

You may want to include full path for ssh and/or asterisk commands, i.e.
View Code/usr/bin/ssh
/usr/sbin/asterisk


Always check your code before deploying.There's no place like ~
RE: Updating asterisk phonebook database VIA ssh unattendedPosted: Friday, April 13, 2018 [13:13:20] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
When database updated, program besides updating Asterisk database, creates XML file for Grandstream DP750 phonebook accessible on LAN. Grandstream checks the file every 12 hours making both phonebooks synchronized.
Also program creates a vCard file (VCF) on a LAN which is accessible and used by Android phone or iPhone.

In one shot all phonebook files updated.There's no place like ~
coding / shellPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group