From: chris on 1 Mar 2010 06:16 On 28/02/10 14:15, Tom Anderson wrote: > Secondly, i have a script which looks like: > > someprog & > someotherprog & > quit() { > shutdown-someprog > shutdown-someotherprog > } > trap quit 0 > while read line; do echo -n ""; done > > The idea is that the script starts some other programs (actually ssh > tunnels), then sits there doing nothing until someone sends it SIGINT or > SIGQUIT (or sends EOF to its stdin) something, at which point it shuts > then down cleanly. What's the point of this? Can't 'screen' do this for you, already?
From: Richard Kettlewell on 1 Mar 2010 06:09 Tom Anderson <twic(a)urchin.earth.li> writes: > Firstly, i hear (from [1]) about a syntax that looks like > $VARIABLE:t. I've never come across that. Is this a csh thing, does > bash have an equivalent, and what does it do? > > Secondly, i have a script which looks like: > > someprog & > someotherprog & > quit() { > shutdown-someprog > shutdown-someotherprog > } > trap quit 0 > while read line; do echo -n ""; done > > The idea is that the script starts some other programs (actually ssh > tunnels), then sits there doing nothing until someone sends it SIGINT > or SIGQUIT (or sends EOF to its stdin) something, at which point it > shuts then down cleanly. > > What's the best way to do the 'sit there doing nothing' part? I'm > using a do-nothing read loop, but that's actually not much good, > because as soon as background it, it stops (blocked on reading from a > stdin which is no longer wired to a keyboard), and doesn't immediately > respond to a SIGINT - > i have to fg it before it dies. I thought about a 'sleep 999d', but > that seems like no less of a kludge. How about: while true; do sleep 1000; done (...and 'echo -n ""' seems to be a strange way to spell 'true' or ':'.) > Thirdly, the trap line is actually: > > trap 'echo -n ""; quit' 0 > > Because if i set the trap action to just 'quit' (as shown above), it > doesn't work. What gives? Beats me. $ cat t #! /bin/bash set -e quit() { echo quitting } trap quit 0 while :; do sleep 1000; done $ ./t ^Cquitting $ -- http://www.greenend.org.uk/rjk/
From: Tom Anderson on 1 Mar 2010 07:08 On Sun, 28 Feb 2010, Chris F.A. Johnson wrote: > On 2010-02-28, Tom Anderson wrote: > >> Secondly, i have a script which looks like: >> >> someprog & >> someotherprog & >> quit() { >> shutdown-someprog >> shutdown-someotherprog >> } >> trap quit 0 >> while read line; do echo -n ""; done >> >> The idea is that the script starts some other programs (actually ssh >> tunnels), then sits there doing nothing until someone sends it SIGINT or >> SIGQUIT (or sends EOF to its stdin) something, at which point it shuts >> then down cleanly. > > someprog & > pid1=$! > someotherprog & > pid2=$! > > quit() { > kill "$pid1" ## shutdown-someprog > kill "$pid2" ## shutdown-someotherprog > } Nope. There's a reason i said "shuts them down cleanly" - this is a situation where kill isn't applicable. > trap quit 0 > while read line; do echo -n ""; done > >> What's the best way to do the 'sit there doing nothing' part? I take it from your response that you think the answer to my question is that what i'm doing is okay, then? tom -- Everyone in the world is doing something without me.
From: Tom Anderson on 1 Mar 2010 07:09 On Mon, 1 Mar 2010, chris wrote: > On 28/02/10 14:15, Tom Anderson wrote: >> Secondly, i have a script which looks like: >> >> someprog & >> someotherprog & >> quit() { >> shutdown-someprog >> shutdown-someotherprog >> } >> trap quit 0 >> while read line; do echo -n ""; done >> >> The idea is that the script starts some other programs (actually ssh >> tunnels), then sits there doing nothing until someone sends it SIGINT or >> SIGQUIT (or sends EOF to its stdin) something, at which point it shuts >> then down cleanly. > > What's the point of this? Can't 'screen' do this for you, already? I guess. That seems like overkill, though, since the script isn't actually interactive - i'd like to be able to & it off into the background, then kill it when i'm finished with it. tom -- Everyone in the world is doing something without me.
From: Tom Anderson on 1 Mar 2010 07:20
On Mon, 1 Mar 2010, Richard Kettlewell wrote: > Tom Anderson <twic(a)urchin.earth.li> writes: > >> Secondly, i have a script which looks like: >> >> someprog & >> someotherprog & >> quit() { >> shutdown-someprog >> shutdown-someotherprog >> } >> trap quit 0 >> while read line; do echo -n ""; done >> >> The idea is that the script starts some other programs (actually ssh >> tunnels), then sits there doing nothing until someone sends it SIGINT >> or SIGQUIT (or sends EOF to its stdin) something, at which point it >> shuts then down cleanly. >> >> What's the best way to do the 'sit there doing nothing' part? I'm using >> a do-nothing read loop, but that's actually not much good, because as >> soon as background it, it stops (blocked on reading from a stdin which >> is no longer wired to a keyboard), and doesn't immediately respond to a >> SIGINT - i have to fg it before it dies. I thought about a 'sleep >> 999d', but that seems like no less of a kludge. > > How about: > while true; do sleep 1000; done Yes, that's better. > (...and 'echo -n ""' seems to be a strange way to spell 'true' or ':'.) True! I have no idea why i thought i should do an echo there. Complete thinko. >> Thirdly, the trap line is actually: >> >> trap 'echo -n ""; quit' 0 >> >> Because if i set the trap action to just 'quit' (as shown above), it >> doesn't work. What gives? > > Beats me. > > $ cat t > #! /bin/bash > set -e > > quit() { > echo quitting > } > > trap quit 0 > > while :; do sleep 1000; done > $ ./t > ^Cquitting Huh. That works for me too, and when i splice that trap line back into my script, that works as well. I swear blind that when i tried that before, it didn't; i must have been doing something odd somewhere. Oh well. Thanks for your help! Now i just need to figure out why the script ignores SIGINT when it's suspended then backgrounded. tom -- Everyone in the world is doing something without me. |