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\" }"
{,Un}commenting is a complex matter with Augeas, because of its nature. The short answer is that Augeas cannot {,un}comment nodes currently.
The reason (and proposed solutions) is detailed in this ticket.
As for the reason why your insert fails, it's because you created a
facle
node instead of anentry
node.facle
is not a known node name insyslog.aug
.So here is something you could do instead:
The first line ensures this change is idempotent. This can be simplified if you use Puppet: you can avoid the complexity of the first line by using
onlyif
.There is not a simple "uncomment this line" facility in Augeas AFAIK. You can use
ins
to locate the existing comment, insert the new entry with theset
commands as you have and then remove the comment.Per request, here's an example of how I set up "serial" and "terminal" for a serial console for GRUB:
The only caveat is that
timeout
has to exist.Actually, I'm not sure this really is a good example, but here it is anyway.