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

Jeremy Portzer jeremyp at pobox.com
Mon Oct 18 16:09:05 EDT 2004


If the script is in the background, a "read" command will normally cause
the script to be suspended, because it's not possible to read from the
terminal if the script is backgrounded.  Then, a command like "fg" would
be necessary to restart the script.  This all works only if the script
was started from that same terminal and is retaining the connection to
the terminal (e.g., the parent bash hasn't been exited or killed). 
Otherwise, the read command will expect that there's a file on standard
input from which it's supposed to read.   If there is no such file, it
will hang indefinitely.

I don't think that what Brian wants to do can be accomplished without
signal handling.  Brian, the "trap" command can be used to capture
signals and define a function to run.  I'm not sure if that can be used
exactly for your purpose, however.

Jeremy

On Mon, 2004-10-18 at 15:41, Ryan Leathers wrote:
> have you tried "read" ? ? don't know if backgrounding it will cause troubles
> but I'll bet you could test it easily enough.  basically read will just wait
> until you press enter.  the variable you set is of no consequence.
>  
> -----Original Message-----
> From: Brian Henning [mailto:brian at strutmasters.com]
> Sent: Monday, October 18, 2004 3:10 PM
> To: TriLUG
> Subject: [TriLUG] Making a bg'd bash script wait for user intervention
> 
> 
> 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?
> 
> Thanks muchly,
> ~Brian
> 
> ----------------
> Brian A. Henning
> Strutmasters.com
> 866.597.2397
> ----------------
> 
> 
> -- 
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ  : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc
-- 
/---------------------------------------------------------------------\
| 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/deef0526/attachment.pgp>


More information about the TriLUG mailing list