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

Jeremy Portzer jeremyp at pobox.com
Mon Oct 18 16:17:39 EDT 2004


On Mon, 2004-10-18 at 15:09, Brian Henning wrote:
> Hi Y'all,
>   I'm working on a set of scripts for backups, and I've hit a snag in a
> script that burns images to CDs.  I need it to wait for user intervention in
> certain situations (no CD in drive, CD not blank, swap CDs now, etc).  I've
> got the various conditions mapped out in the script; all I need is a way to
> make it wait for me to say "go", basically.  The trick is that the process
> may be backgrounded, so it can't be simply waiting for Enter on stdin (or
> can it?).  I tried suspend, but I get
> suspend: cannot suspend: no job control
> 
> Is there another simple method to make a bash script wait for a signal?  Or
> else, what do I need to do to make suspend work?

I just re-read your message after reading Ryan's first, and I see what
you're trying to do with the suspend command.  This looks like an ideal
solution, because you *can't* wait for Enter on stdin, because you don't
really have access to stdin if the script is backgrounded.  However,
silly question... what does the first line of your script look like, is
it this:  #!/bin/sh ?  If so, you are running bash in sh-compatible
mode, which doesn't have job control, and possibly the reason for this
error.  If you change that to /bin/bash it could fix that.  Maybe I'm
OLF, not sure.

You would probably want to write a second "helper" script that would
find the process ID of the first script, and then run "kill -CONT <pid>"
to restart it.

Neat idea, good luck!

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/7204f442/attachment.pgp>


More information about the TriLUG mailing list