Re: Cleanup in a bash script

2024-10-03 Thread tomas
On Thu, Oct 03, 2024 at 03:19:09PM +0300, Anssi Saari wrote: > writes: > > > What actually happens seems completely different to me: the shell > > gets the EPIPE from the dying tee before it can see the EINTR, right? > > That depends. tee -i will ignore SIGINT but ./script gets it. So it can > k

Re: Cleanup in a bash script

2024-10-03 Thread Anssi Saari
writes: > What actually happens seems completely different to me: the shell > gets the EPIPE from the dying tee before it can see the EINTR, right? That depends. tee -i will ignore SIGINT but ./script gets it. So it can keep writing in the pipe, from the script proper or its SIGINT handler and e

Re: Cleanup in a bash script

2024-10-02 Thread Nicolas George
Greg Wooledge (12024-10-02): > In that case, there are THREE foreground processes which receive a SIGINT: > > * The interactive shell, which ignores it, because interactive shells >always ignore SIGINT. You are very right on the rest, but this is a mistake: the interactive shell is not in th

Re: Cleanup in a bash script

2024-10-02 Thread tomas
On Wed, Oct 02, 2024 at 08:17:34AM -0400, Greg Wooledge wrote: [...] Thanks for your (as always) very exhaustive description. > What I'm mostly trying to convey here, though, is that signals do not > *propagate* from one process to another in any kind of automatic way. That's more or less what

Re: Cleanup in a bash script

2024-10-02 Thread Greg Wooledge
On Wed, Oct 02, 2024 at 13:59:04 +0200, to...@tuxteam.de wrote: > On Wed, Oct 02, 2024 at 02:43:11PM +0300, Anssi Saari wrote: > > Running ./script |& tee -i log works as expected. The script gets the > > INT signal and cleans up. > > Understood. > > > To me, "signal passing up the pipe" is an ap

Re: Cleanup in a bash script

2024-10-02 Thread tomas
On Wed, Oct 02, 2024 at 02:43:11PM +0300, Anssi Saari wrote: > writes: [...] > > Explain to us what you really mean by "signals pass up the pipe", then > > things > > might become clearer. > > I realize I didn't spell it out. It's the, to me, obvious solution to > Tim's problem, as he wrote: >

Re: Cleanup in a bash script

2024-10-02 Thread Anssi Saari
writes: > On Tue, Oct 01, 2024 at 01:53:26PM +0300, Anssi Saari wrote: >> Greg Wooledge writes: >> >> > On Mon, Sep 30, 2024 at 14:08:19 +0300, Anssi Saari wrote: >> >> Tim Woodall writes: >> >> >> >> > However on trying to debug something else, I wanted to run it like this: >> >> > >> >> > .

Re: Cleanup in a bash script

2024-10-01 Thread tomas
On Tue, Oct 01, 2024 at 01:53:26PM +0300, Anssi Saari wrote: > Greg Wooledge writes: > > > On Mon, Sep 30, 2024 at 14:08:19 +0300, Anssi Saari wrote: > >> Tim Woodall writes: > >> > >> > However on trying to debug something else, I wanted to run it like this: > >> > > >> > ./script |& tee log >

Re: Cleanup in a bash script

2024-10-01 Thread Anssi Saari
Greg Wooledge writes: > On Mon, Sep 30, 2024 at 14:08:19 +0300, Anssi Saari wrote: >> Tim Woodall writes: >> >> > However on trying to debug something else, I wanted to run it like this: >> > >> > ./script |& tee log >> > >> > and now it doesn't clean up if I it. >> >> Just a point here about

Re: Cleanup in a bash script

2024-09-30 Thread Tim Woodall
On Sat, 28 Sep 2024, Michael Kjörling wrote: On 28 Sep 2024 16:28 +0100, from debianu...@woodall.me.uk (Tim Woodall): Hmmm, I've managed to fix it. The problem seems to be related to using echo in the exit trap itself while both stderr and stdout are redirected - e.g. via |& tee log If I chang

Re: Cleanup in a bash script

2024-09-30 Thread Greg Wooledge
On Mon, Sep 30, 2024 at 14:08:19 +0300, Anssi Saari wrote: > Tim Woodall writes: > > > However on trying to debug something else, I wanted to run it like this: > > > > ./script |& tee log > > > > and now it doesn't clean up if I it. > > Just a point here about tee since I didn't see anyone else

Re: Cleanup in a bash script

2024-09-30 Thread Anssi Saari
Tim Woodall writes: > However on trying to debug something else, I wanted to run it like this: > > ./script |& tee log > > and now it doesn't clean up if I it. Just a point here about tee since I didn't see anyone else mention it. tee has had the -i option to ignore interrupt signals for ages.

Re: Cleanup in a bash script

2024-09-28 Thread Michael Kjörling
On 28 Sep 2024 16:28 +0100, from debianu...@woodall.me.uk (Tim Woodall): > Hmmm, I've managed to fix it. The problem seems to be related to using > echo in the exit trap itself while both stderr and stdout are redirected > - e.g. via |& tee log > > If I change the echo in the trap function to /bin

Re: Cleanup in a bash script

2024-09-28 Thread Tim Woodall
On Sat, 28 Sep 2024, Greg Wooledge wrote: On Sat, Sep 28, 2024 at 14:53:10 +0100, Tim Woodall wrote: Is there a way in bash to guarantee that a trap gets called for cleanup in a script? #!/bin/bash trap cleanup EXIT cleanup() { ... } This works in bash -- i.e., it calls the cleanup functi

Re: Cleanup in a bash script

2024-09-28 Thread Greg Wooledge
On Sat, Sep 28, 2024 at 15:17:47 +0100, Alain D D Williams wrote: > On Sat, Sep 28, 2024 at 10:13:59AM -0400, Greg Wooledge wrote: > > On Sat, Sep 28, 2024 at 14:53:10 +0100, Tim Woodall wrote: > > > Is there a way in bash to guarantee that a trap gets called for cleanup > > > in a script? > > > >

Re: Cleanup in a bash script

2024-09-28 Thread Alain D D Williams
On Sat, Sep 28, 2024 at 10:13:59AM -0400, Greg Wooledge wrote: > On Sat, Sep 28, 2024 at 14:53:10 +0100, Tim Woodall wrote: > > Is there a way in bash to guarantee that a trap gets called for cleanup > > in a script? > > #!/bin/bash > trap cleanup EXIT > cleanup() { > ... > } > > This works i

Re: Cleanup in a bash script

2024-09-28 Thread Greg Wooledge
On Sat, Sep 28, 2024 at 14:53:10 +0100, Tim Woodall wrote: > Is there a way in bash to guarantee that a trap gets called for cleanup > in a script? #!/bin/bash trap cleanup EXIT cleanup() { ... } This works in bash -- i.e., it calls the cleanup function regardless of whether the shell exits b

Re: Cleanup in a bash script

2024-09-28 Thread john doe
On 9/28/24 15:53, Tim Woodall wrote: Is there a way in bash to guarantee that a trap gets called for cleanup in a script? I have a script that works perfectly normally and cleans up after itself, even if it goes wrong. However on trying to debug something else, I wanted to run it like this: ./

Cleanup in a bash script

2024-09-28 Thread Tim Woodall
Is there a way in bash to guarantee that a trap gets called for cleanup in a script? I have a script that works perfectly normally and cleans up after itself, even if it goes wrong. However on trying to debug something else, I wanted to run it like this: ./script |& tee log and now it doesn't