How to read values from db in provision script

I presume you are trying to automatically update the config/firmware on your devices? A more resilient way is outlined in this post.

Also, every time you change an external script, you have to restart the CWMP process for the changes to be picked up.