Reputation: 171
I want to write all stdout of script to a log file by default but want to display some messages on the console as well. Below is the sample code I tried.
#!/bin/bash
LOG='output.txt'
exec 3>&1
exec 1>>$LOG
exec 2>>$LOG
echo "This should be written to log"
echo "This should be written to both screen as well as log"|tee -a >&3
This writes This should be written to log
to the log file, which is good.
It writes This should be written to both screen as well as log
only on the console, but I want it to be written to both console and log.
Upvotes: 2
Views: 200
Reputation: 71
You're missing a filename on your tee command. Try it like this:
echo "This should be written to both screen as well as log"|tee -a $LOG >&3
Upvotes: 2