journalctl looks like a great tool for looking through logs, but I'm stuck on what feels like a simple ask: I want to see all cron messages that contain the phrase update-ipsets
.
Of course I can do this
journalctl -u cron.service | grep update-ipsets
but then you lose all the other benefits of journalctl's output (colour coding, auto paging, live view etc.)
I've tried:
journalctl -u cron.service MESSAGE=update-ipsets
journalctl -u cron.service "MESSAGE=*update-ipsets*"
journalctl -u cron.service "MESSAGE=.*update-ipsets.*"
journalctl -u cron.service "MESSAGE=/.*update-ipsets.*/"
And you don't want to experiment by hitting tab after MESSAGE=
- hangs the (zsh/Debian Jessie) shell and Ctrl-C didn't help either!
I sort of can't believe that it doesn't have this basic functionality built in, so I'm sure I must have missed something?
Thanks.
Since
systemctl --version
version237
there might be grep pattern support with-g/--grep
switch, but it has to be compiled withPRCE2
support (it doesn't appear to be included in Debian Buster,>=242
is needed, it's possible to install in frombuster-backports
)Without grep support you can still switch to
cat
output mode and usegrep
's matching:if you want a pager it's best to pipe the result to
less
. You can use invert matching-v / --invert-match
to exclude certain messagesYet another option is to use
json
format:which gives verbose output, single line
using
jq
you can easily filer messages:Currently, journalctl does not support patterns or wildcards in field matches.
grep
is your best option.I had the same problem, and I think that
journalctl
only searches for an exact match for VALUE whenNAME=VALUE
is passed as arguments.My investigations:
man page
From
journalctl(1)
The pattern is not mentioned in the description of the matches:
The man page refers to a pattern when describing
-u
option only.Source code
The function
fnmatch
insrc/journal
is used when searching for units only.debug journalctl
Enabling debug output you can see that the pattern is expanded only when using
-u
.All the matches are treated as exact, including
UNIT
:With journalctl version 247.3-7 (as systemd), the --grep (or -g) option allows to filter lines in journal where MESSAGE field contain a string or match a regular expression.
man journalctl says :
What is not said neither in the manual of journalctl nor in pcre2pattern, is that the regular expression has to be surrounded by either single or dual quotes and no other character !!!
If you run the following command as root or using sudo :
you will get a list of all recorded block IDs and the request blocked by the firewall...
Hope this help !