-1

On Linux I'm using "tee" to capture the output of "source" command and print it to output log file, but failed. The command I'm using is like this:

source ./my_run.sh 2>&1 | tee -i my_run_log

The intention of my_run.sh is to "make" some compile job, as well as some routine jobs like cd, rm and svn update. The content of my_run.sh is like follows:

  make clean
  cd ..
  rm ./xxx
  svn up -r 166
  cd ./aaa/
  sed -i -e ......
  make compile
  make run

However, when I run it the "tee" just does NOT work, and do NOT give me the log file at all. In order to verify that the entire environment is good, I did a simpler test with:

ll 2>&1 | tee -i log

and in this simpler scenario the "tee" works perfectly fine and prints out "log" as I expected. Can anyone help me find out where my problem is? btw, I'm working on Red Hat Linux (Release 5.9), using bash shell. Thanks in advance!

SOME MORE COMMENTS: I did some more tests and found that as long as the my_run.sh script has got "make xxx" stuffs in it, then "tee" will fail. Seems like tee does NOT like make. Any solutions?

jww
  • 97,681
  • 90
  • 411
  • 885
katyusza
  • 325
  • 2
  • 12
  • Where are you looking for `my_run_log` afterwards? – that other guy Oct 18 '17 at 02:47
  • Hard to say ... all I can say is "It works for me" – tink Oct 18 '17 at 02:48
  • @tink I tried some more combinations and found that, if there're "make xxx" stuffs in the shell, then my "tee" would fail; if shell does NOT have "make xxx", then "tee" works fine. Seems "tee" does NOT like "make"? – katyusza Oct 18 '17 at 03:06
  • @thatotherguy I'm looking for the log file at the current directory where I "source" the script. At least for the simpler "ll 2>&1 | tee -i log" the output log file is located here. – katyusza Oct 18 '17 at 03:07
  • 3
    @katyusza and you're saying that there is no such log file at all at all? Not even an empty one? Does `make clean` delete it by any chance? – that other guy Oct 18 '17 at 03:18
  • 1
    @thatotherguy Yes!! You're right!! The log output was deleted in the **make clean** process!! After fixing the *clean* stuff in the makefile everything is good! Looooooooooooooove you buddy!! – katyusza Oct 18 '17 at 03:32
  • 1
    Please place answers in Answer blocks. Don't add them to the question. That's how Stack Overflow works. – jww Oct 18 '17 at 03:53
  • @jww OK, will do, thanks for the reminder. – katyusza Oct 18 '17 at 03:56
  • @thatotherguy : We now learned that *make* deleted *my_run_log* while `tee` was writing to it. While this solved the problem, I wonder: Shouldn't `tee` then output an error message - kind of "writing to stale file handle" or something? After all it still tries to write to a file, but the file doesn't exist anymore. – user1934428 Oct 18 '17 at 11:10
  • 1
    Unrelated, but running `source` as the first command of a pipeline somewhat defeats the purpose of using `source` in the first place. – chepner Oct 18 '17 at 13:32
  • @user1934428 no, this is a common and useful thing to do for e.g. temp files. The file object itself still exists and works perfectly, it just has one less filename pointing to it. – that other guy Oct 18 '17 at 15:24

1 Answers1

1

Problem solved; many thanks goes to @thatotherguy in leading me to the solution. The log output was actually deleted by the make clean process. After fixing the clean stuff in the makefile, everything is good.

katyusza
  • 325
  • 2
  • 12