Assumming that I have the following in the /etc/syslog.conf
file:
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
I want to change it to kern.* /var/log/kern.log
to get the human-readable timestamp for kernel log.
Puppet can do it:
class syslog::config {
file { "/etc/syslog.conf":
ensure => present,
source => "puppet:///modules/syslog/syslog.conf",
require => Class["syslog::install"],
notify => Class["syslog::service"],
}
}
or I can also use the sed -i
.
With Augeas, I can append this line to the end of file:
class syslog::config {
augeas { "syslogkern":
context => "/files/etc/syslog.conf",
changes => [
"set entry[last()+1]/selector/facility kern",
"set entry[last()]/selector/level *",
"set entry[last()]/action/file '/var/log/kern.log'",
],
}
}
or modify the destination:
class syslog::config {
augeas { "syslogkern":
context => "/files/etc/syslog.conf",
onlyif => "get #comment[3] == 'kern.*\t\t\t\t\t\t\t/dev/console'",
changes => [
"set #comment[3] 'kern.*\t\t\t\t\t\t\t/var/log/kern.log'",
],
}
}
But how do I uncomment this line?
UPDATE
Here's what I've been trying to insert a line after #comment[3]
:
augtool> ins facle after /files/etc/syslog.conf/#comment[3]
augtool> set /files/etc/syslog.conf/facle/selector/facility kern
augtool> set /files/etc/syslog.conf/facle/selector/level *
augtool> set /files/etc/syslog.conf/facle/action/file /var/log/kern.log
or:
augtool> ins facle after /files/etc/syslog.conf/#comment[3]
augtool> set /files/etc/syslog.conf/facle[last()] kernlog
augtool> set /files/etc/syslog.conf/facle[. = 'kernlog']/selector/facility kern
augtool> set /files/etc/syslog.conf/facle[. = 'kernlog']/selector/level *
augtool> set /files/etc/syslog.conf/facle[. = 'kernlog']/action/file /var/log/kern.log
but it didn't work:
augtool> save
error: Failed to execute command
error: saving failed (run 'print /augeas//error' for details)
augtool> print /augeas//error
/augeas/files/etc/syslog.conf/error = "put_failed"
/augeas/files/etc/syslog.conf/error/path = "/files/etc/syslog.conf"
/augeas/files/etc/syslog.conf/error/lens = "/usr/share/augeas/lenses/dist/syslog.aug:243.18-.51:"
/augeas/files/etc/syslog.conf/error/message = "Failed to match \n ({ } | { /#comment/ = /[^\\001-\\004\\t\\n !+-][^\\001-\\004\\n]*[^\\001-\\004\\t\\n ]|[^\\001-\\004\\t\\n !+-]/ } | { /entry/ })*({ /program/ } | { /hostname/ })*\n with tree\n { \"#comment\" = \"Log all kernel messages to the console.\" } { \"#comment\" = \"Logging much else clutters up the screen.\" } { \"#comment\" = \"kern.*\t\t\t\t\t\t\t/var/log/kern.log\" } { \"facle\" = \"kernlog\" } { \"entry\" } { } { \"#comment\" = \"Log anything (except mail) of level info or higher.\" } { \"#comment\" = \"Don't log private authentication messages!\" } { \"entry\" } { } { \"#comment\" = \"The authpriv file has restricted access.\" } { \"entry\" } { } { \"#comment\" = \"Log all the mail messages in one place.\" } { \"entry\" } { } { } { \"#comment\" = \"Log cron stuff\" } { \"entry\" } { } { \"#comment\" = \"Everybody gets emergency messages\" } { \"entry\" } { } { \"#comment\" = \"Save news errors of level crit and higher in a special file.\" } { \"entry\" } { } { \"#comment\" = \"Save boot messages also to boot.log\" } { \"entry\" } { } { } { \"#comment\" = \"INN\" } { } { \"entry\" } { \"entry\" } { \"entry\" }"