[TriLUG] Making a bg'd bash script wait for user intervention

Jeremy Portzer jeremyp at pobox.com
Mon Oct 18 17:00:10 EDT 2004


On Mon, 2004-10-18 at 16:33, Brian Henning wrote:
> <omitting much of the context due to OE attaching PGP messages as text
> attachments and me being lazy>
> All my shell scripts start with #!/bin/bash ..  so there's that idea out the
> window..  Er.. OLF?  Out in Left Field?  heh..
> 
> I would've used killall to automatically find the process, had suspend
> actually suspended..

Well, it looks like we're making this harder than necessary.  The
following script seems to work for me; instead of using suspend, I just
sent the STOP signal to the script itself.

(script is called "test.sh")

#!/bin/bash
 
echo "this is a script"
kill -STOP $$
echo "script has resumed"

then, running the script, and then resuming it, works as desired:

$ ./test.sh | cat &
[1] 31359
$ this is a script
$
$ killall -CONT test.sh
$ script has
resumed                                                                           
[1]+  Done                    ./test.sh | cat

Obviously the prompts are mixed in there with the output from the script
itself, but you get the point.  I piped the script's output to cat so
that the shell saw that the output was being redirected to a pipe,
rather than a tty, which affects how this works.  (Try it both ways and
you'll see how.)

Hope this helps,
Jeremy

-- 
/---------------------------------------------------------------------\
| Jeremy Portzer        jeremyp at pobox.com      trilug.org/~jeremy     |
| GPG Fingerprint: 712D 77C7 AB2D 2130 989F  E135 6F9F F7BC CC1A 7B92 |
\---------------------------------------------------------------------/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.trilug.org/pipermail/trilug/attachments/20041018/459d88de/attachment.pgp>


More information about the TriLUG mailing list