Set extern ip via commandline

I have a public dynamic ip address. I want to write a script, which checks my external ip, updates the external_sip_address and external_media_address for pjsip and restarts asterisk.

Because of FreePBX I can’t only adjust pjsip.transport.conf.

How can I adjust the external IP for PJSIP in FreePBX via commandline? Do I need to adjust the database and do “fw console restart”?