0

If I don't tell the commands in a script to redirect the error stream to a file, can I still get the error messages that that script generated afterward? I'm thinking something like a generic bucket for all the error messages not redirected to specific files.

Motivation is, I have a script which did not work, but it generated an error for sure. I noticed that the error stream was not being redirected, so now I'm trying to know what was the error when the script was run.

And yes, I have already changed the script to redirect the error stream. :-)

Pedro Gordo
  • 1,825
  • 3
  • 21
  • 45
  • Note that stderr is not limited to errors -- it's rather intended to be used for *everything that isn't output* -- status updates, informational messages, etc. – Charles Duffy Apr 13 '18 at 16:09
  • Anyhow -- if you don't do any kind of redirection at all, the contents just stream to your original process's stderr (read: the shell's stderr, which is usually connected to your terminal); they aren't captured or recorded, unless the terminal itself is configured to do logging, or the shell is directing its output to a non-terminal sink. – Charles Duffy Apr 13 '18 at 16:10

1 Answers1

0

You can run your script with this additional parameters to capture errors generated.

your_script.sh > log.txt 2>&1

2>&1 redirects standard error (2) to standard output (1), which then discards it as well since standard output has already been redirected

demircioglu
  • 3,069
  • 1
  • 15
  • 22
  • The OP knows this, and says in the question that they already changed their script to capture stderr for future runs; they're trying to figure out whether they can recover it from a *past* run. – Charles Duffy Apr 13 '18 at 16:14