How to locate a match in unknown key database?

Dear all, I am a newbie on Asterisk.

Currently I wish to do a search for specific variable in a database (in this case is 1001), and i do not know the key in the database. (DB(family/key))

The following is my code:
exten => 500,1,ExecIf($[${DB(family/unknown)=1001}]|DB_DELETE|family/unknown)

What should i enter as the key in order to scan all entries in the database?

Thanks in advance.

Can you post your AstDB entrys? Just use “database show” in the Asterisk CLI.

As following.
CLI> database show hotdesknum
/hotdesknum/1001 : 5001
/hotdesknum/1002 : 5001
/hotdesknum/1004 : 5001
/hotdesknum/3964 : 1002

*In my case, I use “hotdesknum” as my family name, and the keys are my extension numbers. 5001 is my station number.

I wish to preserve the entry /hotdesknum/1001 and delete the rest which are pointing to station 5001.

Any idea? … Thanks.

If you have only 4 database entrys, you can do it with a call to an extension in Asterisk. For instance:

exten => 500,1,ExecIf($[${DB(/hotdesknum/1002)=5001}]?NoOp(Delete entry: ${DB_DELETE(/hotdesknum/1002)}))
exten => 500,n,ExecIf($[${DB(/hotdesknum/1004)=5001}]?NoOp(Delete entry: ${DB_DELETE(/hotdesknum/1004)}))
exten => 500,n,ExecIf($[${DB(/hotdesknum/3964)=5001}]?NoOp(Delete entry: ${DB_DELETE(/hotdesknum/3964)}))
exten => 500,n,Hangup()

The solution does not scale good, but if you have only a few extensions, it should work. If you need a more general solution please explain what you want to do in more detail.

Actually, what I am doing now is hotdesking. When one user sign into a station, one entry as below will be created:
e.g. DB(hotdesknum/1001)=5001

When the user 1001 logout from the station, the entry above will be deleted.

So, if another user 1002 login to the same station 5001, it will create a entry (hotdesknum/1002)=5001.

In this case, when outsider call 1001, the station 5001 will ring if the user 1001 forget to logout from the station.

So, i wish to force logout the previous logged in user from the station by deleting the database entries which is tied to the station when there is a new user login to the station.

And I have 50 users.

Please suggest? Thanks.



Could you please share on how you solved it?

[macro-phone-login] exten => s,1,Set(HUSER=${ARG1}) exten => s,n,Set(PHONE=${ARG2}) exten => s,n,NoOp(Hotdesk user ${HUSER} login into station ${PHONE}) exten => s,n,Set(OLDPHONE=${DB(HOTDESK/${HUSER}/PHONE)}) exten => s,n,Set(OLDHUSER=${DB(HOTDESK/${PHONE}/HUSER)}) exten => s,n,Set(DB(HOTDESK/${OLDHUSER}/PHONE)=) exten => s,n,Set(DB(HOTDESK/${OLDPHONE}/HUSER)=) exten => s,n,Set(DB(HOTDESK/${HUSER}/PHONE)=${PHONE}) exten => s,n,Set(DB(HOTDESK/${PHONE}/HUSER)=${HUSER}) exten => s,n,PlayBack(agent-loginok)

This solution doesn’t suit the title, but it’s a solution on my case = Hotdesk log in. Line no 4 and 5 will delete the previous logged in user when a new user log in into the same station.