user input timeouts?
Kevin D. Clark
kclark at CetaceanNetworks.com
Tue Feb 10 16:27:38 EST 2004
Bob Keyes writes:
> On 10 Feb 2004, Kevin D. Clark wrote:
> > Obviously, there are more complicated ways to do this as well.
>
> Hrm...
Something like this comes to mind:
#!/bin/sh
# ash?
# pass this two arguments:
# first argument: default value if timeout occurs
# second argument: timeout
timed_read() {
trap "echo TIMEOUT ; timed_read_result=$1; return" USR1
child=`sh -c "(sleep $2; kill -USR1 $$) 1>&- 2>&- & echo \\$\\$"`
read timed_read_result
kill $child 1>&- 2>&-
return
}
echo -n "Initiate self-destruct sequence? "
timed_read n 2
echo timed_read_result is $timed_read_result
exit 0
Note: this is a quick hack. It needs polishing. Since I don't work
with ash too often, it seems prudent to let you do the polishing.
Hope this helps,
--kevin
--
Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA)
cetaceannetworks.com!kclark (GnuPG ID: B280F24E)
alumni.unh.edu!kdc
More information about the Discuss
mailing list