0

log=/tmp/log.txt

the follwing syntax write all standard output and stand art error to log.txt file

exec > $log 2>&1

what we want is to write both standard output and stand art error to log.txt but also standard output + standard error to console

is it possible ?

0

There are probably less verbose ways to do this, but the classical solution would be something like:

#!/bin/bash

trap 'rm $TMP' 0
TMP=$(mktemp)
rm $TMP
mkfifo $TMP
tee < $TMP ${log:-/tmp/log.txt} &
exec > $TMP 2>&1

It should go without saying that there are massive security and reliability concerns here, as any other process can read or write from or into the fifo. If you want to do this sort of thing, you're much better off with a simple wrapper that pipes the output of your script to tee.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.