Hello,
I just encountered the same problem with a very similar script. I modified it a bit to use 'tee' to write the file, that seemed to work better. I spent quite a while on this but I still have an issue.
Here's the bit code :
/bin/rm settings.json
# replacing the new IP address
/bin/sed s/IP_ADDRESS/$INET/ settings_template.json | /usr/bin/tee settings.json
/bin/chmod 660 settings.json
/bin/chgrp nas settings.json
For now it is working well as long as I don't use the daemon and start it manually.
The new settings.json is created and owned by root:root, I make it readable and writeable by the group, and then I chown it to the group "nas", which is the group of "debian-transmission". So transmission can read and write in it, and again I can delete it later and create one with a new IP...
But when I let the daemon open the VPN connection, I have other permissions issues. Whenever the script tries to chown, to chgrp, or to sudo, I have the error "Permission denied". I verified, the script is executed as root, there isn't the immuable attribute set...
It's really weird that I can run this perfectly by simply running the VPN client in shell (openvpn --config myconf.conf), but when I use the service (service openvpn start) something is blocking the chown, the chgrp and the sudo commands.
Well I'm kinda happy that I'm not the only one having this issue, that would be great to have some feedback to know if its due to security restrictions, to a misconfiguration or just an issue in the release.
So maybe you can try stopping the service and start it manually, and see whether your script is being executed as expected and the IP in the settings.json changed or not. And what is your version ?
Matthew