brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: journalctl --cursor-file reads only the new entries on every run

Journalctl
~/tips/tip-journalctl-cursor-file-incremental

journalctl --cursor-file=/var/tmp/jc.cursor -u myapp

Remembers where the last run ended in a file, so each run prints only new entries.

A cron job that mails the log should not mail the same lines twice.

With --cursor-file=FILE journalctl starts after the cursor stored in that file, if it exists, and writes the cursor of the last entry back at the end. The first run prints everything that matches and each next run prints only what is new. I like it better than juggling time stamps in a script.

journalctl --cursor-file=/var/tmp/jc.cursor -u myapp

Use one file for each filter. If two different commands share a cursor file, they steal each other’s place. It needs systemd 242 or newer.

Further reading: journalctl(1) manual page

Going deeper: Guide: find out why a Linux service failed, with journalctl

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link