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
37 views
37 views

I'm using the logger command and process substitution for logging my script output to Syslog.

exec > >(logger --id="$$" -p 'local0.info') 2> >(logger --id="$$" -p 'local0.err')

However, that sometimes includes blank lines, like the second line in the example below:

Jun 25 09:27:07 foo bar[13219]: something
Jun 25 09:27:07 foo bar[13219]:
Jun 25 09:27:07 foo bar[13219]: or other

How can I exclude those lines from the logged information?

in Scripting by (275) 7
edited by

Your answer

Preview

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

1 Answer

0 votes
 

From the man page:

-e, --skip-empty
Ignore empty lines when processing files. An empty line is defined to be a line without any characters. Thus a line consisting only of whitespace is NOT considered empty. Note that when the --prio-prefix option is specified, the priority is not part of the line. Thus an empty line in this mode is a line that does not have any characters after the priority prefix (e.g., <13>).

So you just need to add the option -e to your logger commands:

exec > >(logger --id="$$" -e -p 'local0.info') 2> >(logger --id="$$" -e -p 'local0.err')
by (275) 7
...