0

I have the following in my bash script:

# catch input for log-data
exec > >(tee -i ${LOG})
exec 2>&1

I want to exclude one command from being written to this log file, but the following doesn't work:

/sbin/runuser -l USER -c 'COMMAND' >/dev/null 2>&1

It always gets logged to the ${LOG} file.  How can I prevent this?

Omexlu
  • 43
  • 1
  • 9
  • (1) I tried what you say you tried, and the output from the distinguished command did not get written anywhere.  Please clarify what happens when you run it; perhaps giving *real* commands rather than the generic `command`.  (For example, ``date`` seems to write to stdout reliably; for stderr, use ``cat``, ``cp`` and ``ls`` with invalid arguments.)  (2) Your comment is wrong.  You are catching the *output* of subsequent commands, not the input.  (3) You should use ``"$LOG"`` (or ``"${LOG}"``, if you want) rather than ``${LOG}``. – Scott - Слава Україні May 17 '21 at 17:40
  • I have updated, because of exec 2>&1 all errors get logged to the defined file, but i want for /sbin/runuser that the errors don't get logged to the file. – Omexlu May 17 '21 at 17:43

1 Answers1

0

I think i figured it out, my solution is:

Revert the exec command:

exec 1>&2 2>&-

Do the command

Restore the old exec:

exec 2>&1

If there are a better solution, you can tell me :)

Omexlu
  • 43
  • 1
  • 9