delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/19/19:21:44

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Tue, 19 Jun 2001 18:58:55 +0300
Message-Id: <200106191558.SAA24155@linux.>
From: "Ehud Karni" <ehud AT unix DOT simonwiesel DOT co DOT il>
To: "\"\"David A. Cobb\"\"" <superbiskit AT home DOT com>
Subject: Re: One dumb question
CC: cygwin AT cygwin DOT com
In-reply-to: <5.1.0.14.0.20010618114229.03d27610@mail> (message from David A.
Cobb on Mon, 18 Jun 2001 11:46:39 -0400)
Organization: Simon & Wiesel Insurance agency
Reply-to: ehud AT unix DOT simonwiesel DOT co DOT il
References: <5 DOT 1 DOT 0 DOT 14 DOT 0 DOT 20010618114229 DOT 03d27610 AT mail>
X-Mailer: Emacs 20.7.1 rmail (send-msg 1.104)
MIME-Version: 1.0

On Mon, 18 Jun 2001 11:46:39 -0400, David A. Cobb <superbiskit AT home DOT com> wrote:
> Is there a way to get the "current" bash shell to tee its output to a
> logfile?  I remember doing something like this once upon a time but I don't
> recall what I did and I was using a different shell (ksh on an HP/UX).

You can achieve it by the following 3/4 commands:

exec 3>&1                  # create pipe (copy of stdout)
exec 1>bash.dbg            # direct stdout to file       
##  exec 2>&1              # uncomment if you want stderr too
tail -f bash.dbg >&3 &     # run tail in bg              
                           
If you don't redirect stderr, the order of stdout and stderr messages
may be out of original order.

Here is a sample script that tested this on both Linux and Cygwin.

#! /bin/sh -ex

exec 3>&1
exec 1>bash.dbg
    exec 2>&1
tail -f bash.dbg >&3 &

: rest of script

echo "aaa bbb ccc"
: "stderr only"
sleep 5
echo "ddd eee fff"
########### end of test ###########

Ehud.


--
 Ehud Karni     Mivtach - Simon  Insurance   /"\
 Tel: +972-3-6212-757 Fax: +972-3-6292-544   \ /  ASCII Ribbon Campaign
 (USA) Fax and  voice  mail: 1-815-5509341    X   Against  HTML  Mail
     Better     Safe     Than     Sorry      / \
     mailto:ehud AT unix DOT simonwiesel DOT co DOT il    http://www.simonwiesel.co.il

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019