Evaluate systemd logs using journalctl
Analysis Options
Before we had systemd, if your system didn't recognise an external drive such as a USB stick, your only choice was to examine the output of dmesg
using the command tail -n 10
. This would show the last ten lines of output, hopefully displaying when the stick was connected. Journalctl has a built-in function for this. Use journalctl -n <value>
to display the last x number of lines.
System admins also used to use the command tail -f
to keep track of logfiles. On operating systems using systemd, you can now achieve the same thing by running journalctl -f
. By way of example, run the command journalctl -u apache2 -f
. Use Ctrl+C to interrupt the continuous output.
Output to other formats
If you want to analyze a journal in a different way, you can output data to other formats. See Listing 7 for an example of how to save all syslog Error levels as a simple text file. For other file types, use the -o
or --output
to specify the format. The default output is short
and matches the syslog output.
Listing 7
Saving All Syslog Error Levels
The option -o verbose
provides a more comprehensive output with all metadata and fields. Use -o cat
as an alternative to short
. Use the option -o short-monotonic
for a more precise time-stamp. This will allow a more reliable comparison of outputs from different sources.
For further analysis of journal data using web tools, you can use the output options -o json
or -o json-pretty
. If you simply want to send the journal over the network in binary format, use -o export
.
Safety and security
As efficient as the binary files are, if the logs do become corrupted, there's currently no way to repair them. However, their contents will usually be preserved. You can use your built-in Linux commands such as strings
and grep
to filter only uncorrupted data, as shown in Listing 8.
Listing 8
Filtering Only Uncorrupted Data
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs