[Discuss] Bash question

Andrew Resch andrewresch at gmail.com
Fri Aug 15 15:40:28 PDT 2014


Here is an example of using tee to write your stdout/err to a file and the
screen at the same time.

/tmp/mylog will contain stdout
/tmp/myerror will contain stderr


#!/bin/bash

exec > >(tee /tmp/mylog)
exec 2> >(tee /tmp/myerror >&2)
ls /tmp
ls /foobar


On Fri, Aug 15, 2014 at 3:24 PM, John Blomfield <jabfield at shaw.ca> wrote:

> Here is a snippet from a bash script cron job I run:
>
> .............
> if rsync -avz --delete --exclude=lost+found $SOURCEDIR $DESTDIR 1>
> $DEBUGLOG 2> $ERRORLOG; then \
> ..........
>
> Occasionally, I need to run this script manually in a terminal and would
> like to see the output in the terminal as well as saving it to the debug
> and error log files. Any suggestions?
>
> --
> John Blomfield
> Delivered by Thunderbird Email on Linux OpenSuse-KDE4
>
> Old John B's Linux Notes http://www.oldjohnbslinux.wordpress.com
>
>
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://lists.vlug.org/mailman/listinfo/discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://vlug.org/pipermail/discuss_vlug.org/attachments/20140815/581eba6d/attachment.html>


More information about the Discuss mailing list