Search code examples
bashshjqtee

Using tee and jq to write txt and json log files


I'd like to write two log files using tee, first log file as txt, second log file as json

Tee is working for two txt files, but can't get jq to work with tee...

My code:

logfilename="log_download_2017"
echo "start process $(date -u)" | tee -a $logfilename.txt >> jq . $logfilename.json
echo "logfilename" $logfilename | tee -a $logfilename.txt >> jq . $logfilename.json

Console output:

tee: .: Is a directory tee: .: Is a directory

Log files output:

start process Mon May 15 03:14:09 UTC 2017 logfilename log_download_2017


Solution

  • Based on your description, it looks like you want:

     echo "start process $(date -u)" | tee -a "$logfilename.txt" | jq . >> "$logfilename.json"
    

    etc.