0

My sysadmin created a bash script and the first command in it is to redirect the output in a log file:

exec > my_app.log

With this, I have the following:

  • stdout redirected to my_app.log
  • see stderr live in my terminal

When I manually execute the script, I want all of the following:

  • stdout redirected to my_app.log
  • stderr redirected to my_app.err
  • see stdout live in my terminal
  • see stderr live in my terminal

What do I need to change to the exec to have all that to happen?

Currently what I do is open 3 terminals.

  • one to run the script with ./my_script.sh 2> my_app.err
  • one to use tail -f my_app.log
  • one to use tail -f my_app.err

This is too much I think.

Olivier Grégoire
  • 31,286
  • 22
  • 93
  • 132

2 Answers2

1

Take a look at the following link wherein this question has been already answered. Read man page of tee for further details.

Community
  • 1
  • 1
Fazlin
  • 2,252
  • 16
  • 29
1

echo "hello" | tee file.txt

output from echo "hello" put to the file and stdout

if you need stderr and stdout, then echo "hello" 2>&1 | tee file.txt

Ivan Ivanovich
  • 854
  • 1
  • 6
  • 12