2

I have a vpn service unit for which I can view the logs with...

journalctl -u vpn

I also have a script that interacts with the vpn manually and is logged to journal with...

exec > >(systemd-cat -t vpn.sh) 2>&1

and I can view the logs with...

journalctl -t vpn.sh

I tried viewing both logs with...

journalctl -u vpn -t vpn.sh

but it didn't work.

Is there a way to view both logs at the same time? Or is it possible to set the identifier (-t vpn.sh) in the vpn service unit file to match the identifier of my script (vpn.sh).

4

TL;DR: This will work:

$ journalctl _SYSTEMD_UNIT=vpn.service + SYSLOG_IDENTIFIER=vpn.sh

You can use + to connect two sets of connections and look for journal log lines that match either expression. (This is documented in the man page of journalctl.)

In order to do that, you need to refer to them by their proper field names (the flags -u and -t are shortcuts for those.)

You can look at systemd.journal-fields(5) for the documentation of the field names. (That page will also explain why one of them has a leading underscore and the other one doesn't.)

For _SYSTEMD_UNIT you will need an exact match, including the .service suffix (the -u shortcut is smart and will find the exact unit name when translating it to a query by field.)

Putting it all together, you'll get the command above.

0

I found an alternate solution I wanted to post. Some people my find it useful. I can set the SyslogIdentifier under [Service] in the Unit file so that it matches the identifier in my script.

So

[Unit]
Description=vpn management service

[Service]
SyslogIdentifier=vpn.sh
Type=simple
ExecStart=/bin/bash /home/myusername/scripts/vpn.sh

So the identifier will now match that set in vpn.sh when I call the script manually. At the top of the script it is set with..

exec > >(systemd-cat -t vpn.sh) 2>&1

Now to see the logs from both systemd call to vpn.sh and manual call to vpn.sh..

journalctl -t vpn.sh --since today

or

journalctl SYSLOG_IDENTIFIER=vpn.sh --since today

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.