Thread View: comp.unix.shell
6 messages
6 total messages
Started by Larry Lippman
Sun, 21 Oct 1990 04:35
Implementing a Timeout During Shell Script Data Entry
Author: Larry Lippman
Date: Sun, 21 Oct 1990 04:35
Date: Sun, 21 Oct 1990 04:35
36 lines
2342 bytes
2342 bytes
I would be interested in seeing any suggestions for implementing
a timeout for lack of response to a "read" statement contained in a shell
script running under Bourne shell. My purpose for such a requirement is
to permit default values to be automatically entered in a shell script
created for startup purposes without having any user entry whatsoever.
Such a script could, as an example, be run from /etc/rc, crontab, or
manually invoked.
For example, the shell script would echo a data entry prompt and
wait a preset period of time for data entry (via stdin) to occur. If no
data entry occurred, then a shell variable would be set to a default
value; if data entry did occur, the shell variable would be set to the
value returned by the read statement.
Having tried unsuccessfully to accomplish the above by spawning
two processes (one for a sleep, and one for a read), and testing for child
process status (i.e., a return from sleep would kill the read process,
and a return from read would kill the sleep process, etc.), I wrote a
C program 5 years ago that I have been using ever since. The C program
is called from a shell script with one argument for timeout in seconds,
with stdout consisting of a string obtained from characters grabbed from
stdin in raw mode; a null string is sent to stdout if no input occurs.
However, I would really like some greater portability than the
above, and would like to create a situation where the entire function
can be contained with a Bourne shell script.
Anyone have any suggestions? A suitable solution needs to be
"bullet proof" and suitably trap and reset signals in the event of an
operator doing something dumb - a common occurence in the industrial
world! :-)
Larry Lippman @ Recognition Research Corp. "Have you hugged your cat today?"
VOICE: 716/688-1231 {boulder, rutgers, watmath}!ub!kitty!larry
FAX: 716/741-9635 {utzoo, uunet}!/ \aerion!larry
Re: Implementing a Timeout During Shell Script Data Entry
Author: Michael Morrell
Date: Tue, 23 Oct 1990 08:28
Date: Tue, 23 Oct 1990 08:28
19 lines
1058 bytes
1058 bytes
/comp.unix.shell / larry@kitty.UUCP (Larry Lippman) / 9:35 pm Oct 20, 1990/ I would be interested in seeing any suggestions for implementing a timeout for lack of response to a "read" statement contained in a shell script running under Bourne shell. ---------- You might try using the probably undocumented timeout feature of line(1). I'm not sure which versions of Un*x have this "feature", but you could check. It's used as follows: echo "Prompt\c" [ or echo -n "Prompt" ] reply=`line -t 10` The line command will return after 10 seconds if no input has been detected. Hope this helps, Michael
Re: Implementing a Timeout During Shell Script Data Entry
Author: Wm E. Davidsen Jr
Date: Wed, 24 Oct 1990 00:54
Date: Wed, 24 Oct 1990 00:54
21 lines
1321 bytes
1321 bytes
In article <592@DIALix.oz.au> bernie@DIALix.oz.au (Bernd Felsche) writes:
| #!/bin/sh (or korny, if you have it)
|
| delay=6
| trap 'trap 14' 14
| echo "What is your Quest? \c"
| (sleep $delay; kill -14 $$ 2>/dev/null)&
| read YourQuest
| kill $! 2>/dev/null
| [ ! -z "$YourQuest" ] && echo "Bah. Humbug. Not interested in $YourQuest" \
| || echo "You must be interested in something!"
|
| Hope that does the trick.
Works here under sh, not under ksh. No idea.
--
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
sysop *IX BBS and Public Access UNIX
moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me
Re: Implementing a Timeout During Shell Script Data Entry
Author: Ed McGuire
Date: Wed, 24 Oct 1990 16:20
Date: Wed, 24 Oct 1990 16:20
23 lines
1264 bytes
1264 bytes
In article <38020001@hpcuhb.cup.hp.com> morrell@hpcuhb.cup.hp.com (Michael Morrell) writes: > You might try using the probably undocumented timeout feature of line(1). > I'm not sure which versions of Un*x have this "feature", but you could check. > It's used as follows: > > echo "Prompt\c" [ or echo -n "Prompt" ] > reply=`line -t 10` > > The line command will return after 10 seconds if no input has been detected. What version if UNIX are you running? No machine at my site will do it. Alliant Concentrix 5.5 (BSD43) no line(1) Apollo Domain/OS SR10.1/BSD43 no line(1) Digital ULTRIX 3.1 ignores -t Intergraph CLIX 3.0.8 (SYSVR31) ignores -t S.G. IRIX (SYSVR3) ignores -t Stardent OS 2.2 (SYSVR30) ignores -t Sun SunOS (BSD43) ignores -t -- peace. -- Ed "Vote. Because it's the Right Thing."
Re: Implementing a Timeout During Shell Script Data Entry
Author: Michael Morrell
Date: Wed, 24 Oct 1990 22:14
Date: Wed, 24 Oct 1990 22:14
12 lines
1008 bytes
1008 bytes
/comp.unix.shell/emcguire@ccad.uiowa.edu (Ed McGuire) / 9:20 am Oct 24, 1990 > You might try using the probably undocumented timeout feature of line(1). > I'm not sure which versions of Un*x have this "feature", but you could check. What version if UNIX are you running? No machine at my site will do it. ---------- I'm using HP-UX 7.0 (a conglomeration of SysV and BSD4.something), but I fairly sure it's not unique to HP-UX. Also, "line" may be a shell builtin on some systems, which would explain why you don't find a line(1). Michael
Re: Implementing a Timeout During Shell Script Data Entry
Author: Wm E. Davidsen Jr
Date: Mon, 29 Oct 1990 01:19
Date: Mon, 29 Oct 1990 01:19
6 lines
716 bytes
716 bytes
The original suggestion works on Xenix in sh but not ksh.
--
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
sysop *IX BBS and Public Access UNIX
moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads