Technical information on this site may be out of date : no updates since 2015

Log output of a script to a file

July 12 2012 : posted under bash

Nice bit of bash fu I discovered today

Add this snippet to the top of scripts and the output of lines below will be tee’d to a logfile.

Handy for those scripts you always want a log of

#!/bin/bash

# log all output
[ -d ~/logs/ ] || mkdir ~/logs/
exec > >(tee -a ~/logs/${release}.log)
exec 2> >(tee -a ~/logs/${release}.log)

# do stuff ...