Categories
Knowledge Base

Simple Script to import Asterisk Database entries

This is a very simple script to add entries in bulk to the asterisk internal database.

You colate your entries in a simple csv file as below

family,key1,val99
family,key2,val98

then this simple script needs to be written and then run to update the astdb

#!/bin/sh
input=db.csv
while read line
do
 fam=$(echo $line | cut -d',' -f1)
 key=$(echo $line | cut -d',' -f2)
 value=$(echo $line | cut -d',' -f3)
 asterisk -rx "database put $fam $key $value"
done < "$input"

As can be seen its short and simple, but as it does what its meant to do and can save lots of time when building or migrating Asterisk  servers.

It could be easily changed to remove entries if required.