ConfD User Community

How to retrieve CONFD_MAAPI_USID and CONFD_MAAPI_THANDLE from bash

Hi there,
I attempt to write short bash script to read/write some value from the confD DB.
so I can for example do:

confd_cmd -dd -o -c 'maapi_delete "/lldp/enable"'
confd_cmd -dd -o -c 'mcreate "/lldp/enable"'

to crete/delete an entry regarding lldp.

from confd_cli I would type in "lldp enable"/"no lldp [enable]" to perform the same operation .

by reading the ConfD_User_Guide (ver.6.4), ch 16.26.2,

I see that I could use maapi cmd to achieve the same thing (typing the same text as in confd_cli) from bash. But when I attempt to use it

$ maapi --clicmd "no lldp enable"
Error: no CONFD_MAAPI_USID environment variable found

I also read from in “ENVIRONMENT VARIABLES” that

The CONFD_MAAPI_USID and CONFD_MAAPI_THANDLE environment variables are automatically set by ConfD when invoking a CLI command

so I assume this should somehow be set automatically. which it isn’t. What am I missing?

Thank you in advance for your help.

The command maapi serves a bit different purpose than confd_cmd: maapi attaches to an existing user transaction and does all its changes or takes all data from that transaction - i.e. so as to use maapi a user session and a transaction must already exist. The typical use is in scripts that are run as custom CLI commands: when ConfD starts such scripts, it sets CONFD_MAAPI_USID and CONFD_MAAPI_THANDLE environment variables that are used by maapi to attach to the CLI session.

It can be used for other sessions too, not only interactive CLI sessions, but some options such as --clicmd would not work elsewhere.

See the maapi manual or documentation pages for more details.