[comp.unix.shell] How to do non-blocked I/O?

peter@aucs.AcadiaU.ca (Peter Steele) (06/05/91)

I want to modify our system startup scripts to ask a question like

    Okay to bring up databases (y/n)?

and if there is no reply within, say 5 seconds, assume "y". Can
I do this from sh or csh or do I have to write a C program to
do the I/O? If a C program is required, can someone point me
to the best reference on how to do non-blocking I/O? Thanks.
-- 
Peter Steele  Postmaster  peter.steele@acadiau.ca   Tel: 902-542-2201
Software Analyst, Acadia University, Wolfville, NS  Fax: 902-542-7224

Dan_Jacobson@ATT.COM (06/12/91)

>>>>> "Peter" == Peter Steele <peter@aucs.acadiau.ca> writes:

Peter> I want to modify our system startup scripts to ask a question like

Peter>     Okay to bring up databases (y/n)?

Peter> and if there is no reply within, say 5 seconds, assume "y". Can
Peter> I do this from sh or csh

Most major dudes [<- Steely Dan musical reference there] frown upon
csh, so that leaves sh.  This works in ksh & sh, so it probably works
in bash too (note SYS Vish "\c" for echo though... no big deal)

#just examples
program="screen -r || screen" #maybe set this in a case statement

test -n "$program" &&
	sec=8 &&
	trap 'trap 2' 2 &&
	echo "you got $sec seconds to interrupt before
		\"$program\"... \c" &&
	sleep $sec &&
	trap 2 &&
	eval $program