AppleScript C Perl Shell Xcode Other

Updating asterisk phonebook database VIA ssh unattended

Post Reply
coding / shell     Views: 21Prev .. Next
Updating asterisk phonebook database VIA ssh unattendedPosted: Thursday, October 12, 2017 [07:54:32] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 134
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 del tree - 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\''
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'

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

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

Always check your code before deploying.There's no place like ~
coding / shellPrev .. Next
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other