PracticalWeb Ltd

Websites that work for you.

Log Output of a Script to a File

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 …

Comments