sometimes I want to automatically add a config to a conf file that I can scriptably remove later, for example I want to temporarily make 10 hosts log to a remote syslog server. So I so something like this in a script;
##some other commands
echo "kern.* @syslog.server.local" >> /etc/syslog.conf
service syslogd restart
however quite often I update the some other commands and run the script again. obviously this is not idempotent, I can't re-apply it without some grep/delete jiggerpokery and I can't easily remove it.
so I have taken to doing something like this;
cat <<HEREDOC >>/etc/syslog.conf
###some unique string###
echo "kern.* @syslog.server.local"
###end some unique string###
HEREDOC
which allows me to do this to make the operation repeatable...
sed -e 's/###some unique string###(*)###end some unique string###/replacement/g' /tmp/syslog.conf > /tmp/syslog.conf
cat <<HEREDOC >>$dfile
###some unique string###
echo "kecrn.* @syslog.server.local"
###end some unique string###
HEREDOC
however this all seems a bit much...
(obviously /etc/httpd/conf.d/someconffile.conf arrangements have solved this problem for newer packages)
is there a simpler way to do this ?
any caveats that I should be aware of with this approach?