Output bash script to both the journal and console

223 Views Asked by At

I'm trying to write a script that will output the results of a command to both the console and journal, while keeping the stderr set at a higher priority than stdout.

systemd-cat does it, but it doesn't log the results to the console. I tried using journal but I was getting the same results and it wasn't setting the priority based on the stream because it all had to go to STDOUT to get piped in to it.

For example

systemd-cat -t test --stderr-priority=7 bash -c "cd /negative; pwd"
1

There are 1 best solutions below

1
KamilCuk On

logger been with us for some time now.

{
    cd /negative
    pwd
} 2>&1 | logger -s -p 7 -t test