In order to automate some system update functionality I have written some BASH scripts.
What I want to achieve is to redirect stdout and stderr to a log file and stderr to the terminal running the script.
This is what I have come up with so far:
((./cmd >logfile) 2>&1) | tee logfile
Note ./cmd is a placeholder here, in my script it is actually an ssh call into one of my machines.
The unfortunate thing is that writing to the same file from two different processes is not ideal. My update.log obviously shows signs of the two writes stomping on each other.
I want the log to interleave so the errors thrown are close to the relevant standard output, thus writing to separate files and merging them afterwards is not really an option.
Any suggestions would be greatly appreciated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…