There are only 2 lines in my /etc/sysconfig/syslog file that aren't commented out.
To check if a file exists, try something like (in Bash):
if [[ -f $file ]]; then
#file exists and is a regular file (ie no directory, symlink or whatever).
#you may want to check if it's writable too by using a similar if [[ -w $file ]]; test.
#Add error message here to indicate that file doesn't exist.
echo "File $file does not exist on this system. No changes made."
#Exit with non-zero exit value to indicate an error.
Check out "man bash" for details on -f, -w and similar tests.
To append "-r" to a specific line, you can use sed or awk.
Or source the syslog file in Bash to get the variables $SYSLOGD_OPTIONS directly, modify them and then write them back into the file, like so:
#Now you have the $SYSLOGD_OPTIONS variable, just append -r to it's value:
#similar for KLOGD_OPTIONS.
#Now write back both variables:
echo "SYSLOGD_OPTIONS=\"$SYSLOGD_OPTIONS\"" >> some_file
mv some_file /etc/sysconfig/syslog
There may be better ways for writing the values back (this method will disregard any lines in the config that you didn't write back explicitly), but hey, this is just an example.