zsh-workers
 help / color / mirror / code / Atom feed
* Re: Tee all output to log file?
       [not found] <alpine.LNX.2.01.1102011836170.2792@hp>
@ 2011-02-02  5:04 ` ZyX
  2011-02-02 17:28   ` Benjamin R. Haskell
  0 siblings, 1 reply; 4+ messages in thread
From: ZyX @ 2011-02-02  5:04 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: Text/Plain, Size: 1298 bytes --]

Reply to message «Tee all output to log file?», 
sent 02:41:26 02 February 2011, Wednesday
by Benjamin R. Haskell:

> Is there something straightforward that I'm overlooking?  Is there a
> commonly used utility for this?  (`script` comes to mind, but I recall
> klunkiness when trying it in the past.)
If you don't like script, maybe you should try screen:

    (( $+logfile )) && \
        exec screen -L -c =(echo "logfile $logfile") -m -S script-$0 $0 $@

(probably needs some escaping of $logfile).

Does anybody know, why it does not work when I start screen in detached mode?

Original message:
> For scripting purposes I occasionally want a way to both record and
> display all the output of a script.  On several occasions now, I've
> looked through the output redirection section of the manual, but I never
> come up with quite what I'm looking for.
> 
> Essentially, when I want this, I usually want something like:
> 
> #!/bin/zsh
> (( $+logfile )) && exec |& tee $logfile
> 
> Boiled down even further, it's really just this I'm looking for:
> exec |& tee logfile
> 
> Is there something straightforward that I'm overlooking?  Is there a
> commonly used utility for this?  (`script` comes to mind, but I recall
> klunkiness when trying it in the past.)

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Tee all output to log file?
  2011-02-02  5:04 ` Tee all output to log file? ZyX
@ 2011-02-02 17:28   ` Benjamin R. Haskell
  2011-02-02 18:05     ` ZyX
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin R. Haskell @ 2011-02-02 17:28 UTC (permalink / raw)
  To: ZyX; +Cc: zsh-workers

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1648 bytes --]

On Wed, 2 Feb 2011, ZyX wrote:

> Reply to message «Tee all output to log file?»,
> sent 02:41:26 02 February 2011, Wednesday
> by Benjamin R. Haskell:
>
>> Is there something straightforward that I'm overlooking?  Is there a 
>> commonly used utility for this?  (`script` comes to mind, but I 
>> recall klunkiness when trying it in the past.)
> If you don't like script, maybe you should try screen:
>
>    (( $+logfile )) && \
>        exec screen -L -c =(echo "logfile $logfile") -m -S script-$0 $0 $@

I find `screen` even more annoying than `script` for scripting purposes, 
wonderful though it is for interactive use.

I really just want the redirection, not the many extra features that 
`screen` adds.

Adding


> Does anybody know, why it does not work when I start screen in detached mode?

Cf. above annoyance.  For doing something with Vim under Apache (using 
:TOhtml), I recently resorted to this hackery:

screen -q -d -m -S $sessionname vim -u NONE -N +'so $scriptname'
(Then, loop, waiting for one of:
1: the Vim script to touch a marker file that indicated completion
2: a specified timeout, in case something errored out, preventing a 
clean Vim exit
)
screen -X -S $sessionname quit



Despite my annoyance (I'm easily annoyed), I tried your above 
suggestion.  It didn't capture stderr, so I added a flag that logging 
was in progress and added a redirect for it (also added '-q' to the 
`screen` commands):

(( $+logfile && ! $+doinglogging )) \
    && exec env doinglogging=true screen -L -c =(echo "logfile $logfile") -q -m -S script-$0 $0 $@
(( $+doinglogging )) && exec 2>&1

Seems okay for what I'm doing.

Thanks,
Ben

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Tee all output to log file?
  2011-02-02 17:28   ` Benjamin R. Haskell
@ 2011-02-02 18:05     ` ZyX
  2011-02-02 18:13       ` Benjamin R. Haskell
  0 siblings, 1 reply; 4+ messages in thread
From: ZyX @ 2011-02-02 18:05 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: Text/Plain, Size: 2157 bytes --]

Reply to message «Re: Tee all output to log file?», 
sent 20:28:13 02 February 2011, Wednesday
by Benjamin R. Haskell:

>     && exec env doinglogging=true ...
I used to write this as «doinglogging=true exec ...» or with
    doinglogging=true
    exec ...
Any reason why env command should envoked here I am not aware of?

Original message:
> On Wed, 2 Feb 2011, ZyX wrote:
> > Reply to message «Tee all output to log file?»,
> > sent 02:41:26 02 February 2011, Wednesday
> > 
> > by Benjamin R. Haskell:
> >> Is there something straightforward that I'm overlooking?  Is there a
> >> commonly used utility for this?  (`script` comes to mind, but I
> >> recall klunkiness when trying it in the past.)
> > 
> > If you don't like script, maybe you should try screen:
> >    (( $+logfile )) && \
> >    
> >        exec screen -L -c =(echo "logfile $logfile") -m -S script-$0 $0 $@
> 
> I find `screen` even more annoying than `script` for scripting purposes,
> wonderful though it is for interactive use.
> 
> I really just want the redirection, not the many extra features that
> `screen` adds.
> 
> Adding
> 
> > Does anybody know, why it does not work when I start screen in detached
> > mode?
> 
> Cf. above annoyance.  For doing something with Vim under Apache (using
> 
> :TOhtml), I recently resorted to this hackery:
> screen -q -d -m -S $sessionname vim -u NONE -N +'so $scriptname'
> (Then, loop, waiting for one of:
> 1: the Vim script to touch a marker file that indicated completion
> 2: a specified timeout, in case something errored out, preventing a
> clean Vim exit
> )
> screen -X -S $sessionname quit
> 
> 
> 
> Despite my annoyance (I'm easily annoyed), I tried your above
> suggestion.  It didn't capture stderr, so I added a flag that logging
> was in progress and added a redirect for it (also added '-q' to the
> `screen` commands):
> 
> (( $+logfile && ! $+doinglogging )) \
>     && exec env doinglogging=true screen -L -c =(echo "logfile $logfile")
> -q -m -S script-$0 $0 $@ (( $+doinglogging )) && exec 2>&1
> 
> Seems okay for what I'm doing.
> 
> Thanks,
> Ben

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Tee all output to log file?
  2011-02-02 18:05     ` ZyX
@ 2011-02-02 18:13       ` Benjamin R. Haskell
  0 siblings, 0 replies; 4+ messages in thread
From: Benjamin R. Haskell @ 2011-02-02 18:13 UTC (permalink / raw)
  To: ZyX; +Cc: zsh-workers

[-- Attachment #1: Type: TEXT/PLAIN, Size: 688 bytes --]

On Wed, 2 Feb 2011, ZyX wrote:

> Reply to message «Re: Tee all output to log file?»,
> sent 20:28:13 02 February 2011, Wednesday
> by Benjamin R. Haskell:
>
>>     && exec env doinglogging=true ...
> I used to write this as «doinglogging=true exec ...» or with
>    doinglogging=true
>    exec ...
> Any reason why env command should envoked here I am not aware of?

Nope, but it doesn't hurt much.  'env' execs, AFAIK, so it's only an 
extra (light) process startup.  Mainly I was lazy.

Accidentally wrote it as:

&& exec doinglogging=true screen ...

Didn't work, since I'd put the precmd modifiers in the wrong order, and 
I tacked on 'env' instead of rearranging.

-- 
Best,
Ben

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-02 18:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <alpine.LNX.2.01.1102011836170.2792@hp>
2011-02-02  5:04 ` Tee all output to log file? ZyX
2011-02-02 17:28   ` Benjamin R. Haskell
2011-02-02 18:05     ` ZyX
2011-02-02 18:13       ` Benjamin R. Haskell

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).