Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
296 views
296 views

My scripts frequently use process substitution for passing script output to syslog:

tag="$(basename "$0")"
exec > >(logger -p local0.info -t "$tag" --id="$$" -e) 2> >(logger -p local0.err -t "$tag" --id="$$" -e)

However, after switching to Ubuntu Jammy these scripts started to produce a weird error:

logger: send message failed: Invalid argument

and the first message from the script does not appear in syslog (subsequent messages do, though).

#!/bin/bash
exec > >(logger -p local0.info --id="$$")
echo "foo"     # 1st message throws error, message not logged
echo "bar"     # subsequent messages logged correctly, no error
echo "baz"

The issue seems to be caused by the parameter --id="$$" in combination with passing messages via STDIN. When passing the message as an argument or omitting the parameter --id="$$" everything works fine.

me@localhost:~ $ echo "foo" | logger -p local0.info --id="$$"  # error, message not logged
logger: send message failed: Invalid argument
me@localhost:~ $ logger -p local0.info --id="$$" "foo"         # no error, message logged
me@localhost:~ $ echo "foo" | logger -p local0.info            # no error, message logged

However, I do want the script PID logged with the message, otherwise distinguishing log messages from different instances of the same script would become a problem. Hence simply omitting --id="$$" is not an option.

This seems to happen only on Ubuntu Jammy, not on older Ubuntu releases (e.g. Xenial) and also not on Devuan.

Addendum:

On Ubuntu the problem seems to occur only in (LXD) containers.

in Scripting
edited by
by (115)
2 18 33
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

This appears to be a recently introduced bug in the logger command. I filed a bug report.

As a workaround you can omit the parameter --id="$$" and instead add the script PID to the tag:

tag="$(basename "$0")[$$]"
exec > >(logger -p local0.info -t "$tag" -e) 2> >(logger -p local0.err -t "$tag" -e)
by (115)
2 18 33
edit history
...