I wrote the following bash function:
function log {
echo "[$(date -u +'%Y-%m-%dT%H:%M:%S.000')]: $*" | tee -ai $logfile
}
Intending that the output of the commands will be printed to both the console and the log.
Edit:
This is how I'm using the function in the script:
log ls -l
In reality, the log contains the commands and not their output, while I want the output to go both to the console and the log while adding the date and time only to the line of the command itself in the log.
How can it be done?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…