Is there a way in AEM we can update the OSGI config with groovy.
I wouldn't want to be using the Groovy console to change any configurations in the OSGI console. The standard way to update custom code package configurations will be to place configuration under /apps/my-app/configs/*; a full tutorial here. https://helpx.adobe.com/uk/experience-manager/6-3/sites/deploying/using/configuring-osgi.html.
For automation, It's better to use a curl command, https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations, where you can write automation scripts to update your OSGI configurations.
This should be helpful: https://aemsimplifiedbynikhil.wordpress.com/2020/08/15/executing-groovy-scripts-using-postman-and-gr...
If you have repository based configuration then only you should use groovy, otherwise use curl to update web console based osgi console.