Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Output errors of nohup to syslog

I'm attempting to write a bash script that uses nohup and passes errors to rsyslog.

I've tried this command with different variations of the log variable (see below) but can't get the output passed to anything but a std txt file. I can't get it to pipe.

nohup imageprocessor.sh > "$LOG" &

Is it possible to pipe nohup output or do I need a different command.

A couple of variations of log that I have tried

LOG="|/usr/bin/logger -t workspaceworker -p LOCAL5.info &2"

or

LOG="|logtosyslog.sh"

or

LOG="logtosyslog.sh"
like image 482
Stephen Baugh Avatar asked Dec 19 '25 13:12

Stephen Baugh


2 Answers

A way in bash to redirect output to syslog is:

exec > >(logger -t myscript)

stdout is then sent to logger command

exec 2> >(logger -t myscript)

for stderr

like image 115
Stephane Rouberol Avatar answered Dec 21 '25 05:12

Stephane Rouberol


Not directly. nohup will detach the child process, so piping the output of the nohup command isn't helpful. This is what you want:

nohup sh -c 'imageprocessor.sh | logger'
like image 27
Nicholas Wilson Avatar answered Dec 21 '25 06:12

Nicholas Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!