Execute a Command in a .Dat File and use it in other Files

We have a process where we store the database password in a config file like below from where the password is picked up and used in Database Scripts

ID, Password

But we now have a Audit Requirement not to have the passwords in Config Files directly. We have a command which could fetch the password from external link

So wanted to check if we could have that executable command in the config file

Something like :
ID, `Executable Command`

So that when the above file is being used in database script it resolves the password

Maybe.
Depends upon how the config file is made available to the script.
If the config file is a list of ordered pairs:

user<separator>username
base_directory<separator>/home
etc

then the answer is no, if however the config file looks like:

user=username; export user
password=abcdef; export password

and the config file is included in the script with

. config_file

then changing the password line to:

password=$(getpasswd); export password

should work.

You can't generally put commands in config files, that's why they're config files and not full-blown scripts. You may actually have to modify your scripts.

This is often done with wrappers to make it less difficult. Instead of mydbms you run some other command which runs mydbms with the same arguments / environment plus a password. This file would be protected by access permissions to prevent it being publicly readable, so you'd have to use sudo to run it, and make sure only the relevant user can sudo for only that file, etc.

Exact details depend on what exactly you're doing.