Unrecognised escape sequence '\[' in file

133 views
Skip to first unread message

Brian Wilkins

unread,
Aug 27, 2014, 8:31:39 AM8/27/14
to puppet...@googlegroups.com
I am having to escape a regular expression in my match and puppet complains on the puppetmaster of an "Unrecognised escape sequence". How do I fix this so the logs don't get cluttered with this message? I am using Puppet 3.6.2.

 file_line { "nagios_monitor_check_${title}":
    path   => '/etc/nagios/nrpe.cfg',
    line   => "command[check_${title}]=/usr/lib64/nagios/plugins/check_procs ${proc_check} ${proc_count}",
    match  => "^command\[check_${title}\]=.*",
    notify => Service[nrpe],
  }

Matthias Saou

unread,
Aug 27, 2014, 11:07:49 AM8/27/14
to puppet...@googlegroups.com
Shot in the dark : Have you tried with two backslashes '\\' ? Because
since you're interpolating $title and have double quotes, it could be
needed to get the regexp string to contain a single backslash.

Also, but why not manage multiple files in /etc/nagios/nrpe.d/ based on
templates instead of managing a single file, since that's much trickier?

Another useless note : You don't need the '.*' at the end of your regexp
if you're not ending it with '$'.

Last useless note : I have also encountered problems with the file_line
'match' parameter, the first one being that the official example is
broken as the 'line' must match the 'match' regexp.

Good luck :-)

Matthias

Brian Wilkins

unread,
Aug 27, 2014, 11:24:21 AM8/27/14
to puppet...@googlegroups.com
Have you tried with two backslashes '\\' ?

Ah, that was it :)


Also, but why not manage multiple files in /etc/nagios/nrpe.d/ based on
templates instead of managing a single file, since that's much trickier?

Oh, that is how I am doing it (sort of):

 class profiles::nagios_resource::vsftpd_check (
  $check_interval = $profiles::nagios_resource::settings::check_interval,
  $group = $profiles::nagios_resource::settings::group,
  $mode = $profiles::nagios_resource::settings::mode ) {

  profiles::nagios_resource::service_check { 'vsftpd': }

}

You don't need the '.*' at the end of your regexp if you're not ending it with '$'.

Hmm, will have to try that and see the effects.

Thanks for the reply.


Wil Cooley

unread,
Aug 27, 2014, 12:45:45 PM8/27/14
to puppet-users group
On Wed, Aug 27, 2014 at 8:24 AM, Brian Wilkins <bwil...@gmail.com> wrote:
Have you tried with two backslashes '\\' ?

Ah, that was it :)

An alternative is to "quote" the bracket by making it a character class: "[[]"

I used to like this for some reason, but I cannot quite remember why now; it certainly isn't more readable. I guess maybe because it avoids having to figure out backslashing (which is especially nasty if you're running awk with shell environment variable interpolation, within "sh -c" that's being run by sudo over a remote shell).

Wil
Reply all
Reply to author
Forward
0 new messages