-1

bash4.2, centos


the script

#!/bin/bash

LOG_FILE=$homedir/logs/result.log
exec 3>&1
exec > >(tee -a ${LOG_FILE}) 2>&1
echo
    
end_shell_number=10

for script in `seq -f "%02g_*.sh" 0 $end_shell_number`; do
    if ! bash $homedir/$script; then
        printf 'Script "%s" failed, terminating...\n' "$script" >&2
        exit 1
    fi
done

It basically runs through sub-shells number 00 to 10 and logs everything to a LOG_FILE while also displaying on stdout.

I was watching the log getting stacked with tail -F ./logs/result.log, and it was working nicely until the log file suddenly got removed.

The sub-shells does nothing related to file descriptors nor the log file. They remotely restart tomcats via ssh commands.


Question :
tee was writing on a log file successfully until the file gets erased and logging stops from then on.
Is there a filesize limit or timeout in tee? Is there any known behavior of tee that it deletes a file?

Lunartist
  • 394
  • 1
  • 3
  • 9
  • Note, that you are asking specifically solely about tee, not your actual problem. Is it XY question? – KamilCuk Aug 05 '21 at 09:10
  • Do you have more than one `tee` writing to the same file (as you did in [this question](https://stackoverflow.com/questions/68659607/can-i-stop-tee-temporarily-in-a-shell-script))? – Gordon Davisson Aug 05 '21 at 09:11
  • @GordonDavisson I removed that logic and only use `exec > >(tee -a ${LOG_FILE}) 2>&1` – Lunartist Aug 05 '21 at 09:17
  • Aside from the correct answer by KamilCuk, I would not redirect stderr. If there is any problem with writing it to the output file, you won't get any hint what's going wrong. – user1934428 Aug 05 '21 at 09:37

1 Answers1

2

On what occasion does 'tee' deletes the file it was writing on?

tee does not delete nor truncate the file once it has started writing.

Is there a filesize limit or timeout in tee?

No.

Is there any known behavior of tee that it deletes a file?

No.

Note that file can be removed, but the process (tee) still will wrote the open file descriptor, but the file will not be accessible (see man 3 unlink).

KamilCuk
  • 120,984
  • 8
  • 59
  • 111