Curator: how to escape characters of "--timestring" in systemd?

I tried to set up a task in systemd but I'm not able to escape the characters used in the parameter "--timestring". For example:

docker run user/curator --host x.x.x.x --port 9200 --dry-run delete indices --older-than 5 --time-unit days --timestring %Y.%m.%d

If I execute the previous command on the command line it works fine but when I tried to include it in a systemd timer task it failed with the following message:

Jul 09 11:43:43 coreos03 docker[31904]: 2015-07-09 09:43:43,302 INFO      Job starting: delete indices
Jul 09 11:43:43 coreos03 docker[31904]: Traceback (most recent call last):
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/bin/curator", line 9, in <module>
Jul 09 11:43:43 coreos03 docker[31904]: load_entry_point('elasticsearch-curator==3.2.0', 'console_scripts', 'curator')()
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/curator/curator.py", line 5, in main
Jul 09 11:43:43 coreos03 docker[31904]: cli( obj={ "filters": [] } )
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in __call__
Jul 09 11:43:43 coreos03 docker[31904]: return self.main(*args, **kwargs)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main
Jul 09 11:43:43 coreos03 docker[31904]: rv = self.invoke(ctx)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke
Jul 09 11:43:43 coreos03 docker[31904]: return _process_result(sub_ctx.command.invoke(sub_ctx))
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke
Jul 09 11:43:43 coreos03 docker[31904]: return _process_result(sub_ctx.command.invoke(sub_ctx))
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke
Jul 09 11:43:43 coreos03 docker[31904]: return ctx.invoke(self.callback, **ctx.params)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke
Jul 09 11:43:43 coreos03 docker[31904]: return callback(*args, **kwargs)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/curator/cli/index_selection.py", line 80, in indices
Jul 09 11:43:43 coreos03 docker[31904]: working_list = apply_filter(working_list, **f)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/local/lib/python2.7/dist-packages/curator/api/filter.py", line 114, in apply_filter
Jul 09 11:43:43 coreos03 docker[31904]: p = re.compile(pattern)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/lib/python2.7/re.py", line 194, in compile
Jul 09 11:43:43 coreos03 docker[31904]: return _compile(pattern, flags)
Jul 09 11:43:43 coreos03 docker[31904]: File "/usr/lib/python2.7/re.py", line 251, in _compile
Jul 09 11:43:43 coreos03 docker[31904]: raise error, v # invalid expression
Jul 09 11:43:43 coreos03 docker[31904]: sre_constants.error: bogus escape: '\\7'

I tried to escape that characters using:

$ systemd-escape %Y.%m.%d
\x25Y.\x25m.\x25d
$

But it fails with the same message. Somebody knows how to execute that curator line in a systemd timer task??

I stumbled over the same issue today on CoreOs.
I found that a single percent is escaped as '%%'.
Things will work if you write:

--timestring '%%Y.%%m.%%d'

(from http://www.freedesktop.org/software/systemd/man/systemd.unit.html)

Cheers,
Michael

2 Likes

Thanks for this! I will add it as a FAQ to the Curator documentation!

1 Like