On Fri, 2021-10-22 at 08:42 +, DHAIY DHAIY wrote:
> But is there a way to insert one string from command-line into
> myservice's journal so that it can be seen byjournalctl -u myservice
> later
Try this:
$ echo "foo" | systemd-cat -t foobar
Then you can access your string with:
$
This option was added with util-linux v2.25 in 2014. If you're using an
older version or the Busybox `logger` instead, well, it won't have that.
The alternative is to write your own C tool that uses libsystemd and calls
sd_journal_send
If you have root privileges (i.e. UID 0), then yes, you can send a journal
message with the "OBJECT_SYSTEMD_UNIT=myservice.service" field and
journalctl will automatically look for that.
In C, specify the field when calling sd_journal_sendv(); in bash you can
use `logger --journal`:
(echo
Saying we have a systemd unit named "myservice".
we can use journalctl -u myservice to inspect the logs generated by myservice.
But is there a way to insert one string from command-line into myservice's
journal so that it can be seen by journalctl -u myservice later?