See if the method for appending to the hosts file is re-usable for your use case. Just need to change the file and line being inspected for, and if you prefer, just keep the parts relevant to the Linux platform.
All you may need to then do is add the command to restart the syslog service