On 6 March 2015 at 14:38, Daurnimator <q...@daurnimator.com> wrote:
> sd_journal_query_unique() finds unique *field names*.
> Not journal entries.

Apologies, I described this incorrectly.

sd_journal_query_unique() takes a field name, and allows you to
iterate over all different values that field has taken.

To accomplish a wildcard or pattern matched search, you can iterate
through unique fields, adding all that meet your pattern as matches.

Here is an example lua program that will print (in reverse) matches
for the given field and (lua) pattern:

#!/usr/bin/env lua
--[[
Depends on lua-systemd: https://github.com/daurnimator/lua-systemd
]]

local sj = require "systemd.journal"

local field = assert(arg[1], "need to provide field name")
local patt = assert(arg[2], "need to provide a pattern")

local j = assert(sj.open())

assert(j:seek_tail())
assert(j:flush_matches())
local has_at_least_one = false
for value in j:each_unique(field) do
    if value:match(patt) then
        has_at_least_one = true
        assert(j:add_match(field.."="..value))
    end
end
if not has_at_least_one then
    io.stderr:write("no matches found\n")
    os.exit(1)
end
assert(j:add_disjunction())
while j:previous() do
    print(j:get("_SYSTEMD_UNIT"), j:get("MESSAGE"))
end
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to