[NTLUG:Discuss] Prompt / Response / Timeout in a script

Jim Goode JGoode at GoToLearn.org
Wed Sep 15 13:33:09 CDT 2004


Here's a possible solution. The timeout period is always observed, 
regardless how quick they input data.

Main shell script:
#!/bin/bash
echo "Enter 1, 2, or 3:[1]"
result=`./timeout`

Timeout shell script:
#!/bin/bash
(sleep 5; kill $$)&               # sleep can be however many seconds 
you need it to be
read result
kill $!


Jack Snodgrass wrote:

>I need a simple ( not perl or any other add-on language ) way to prompt
>a user, take their input or continue on if a timeout period is reached.
>I want to do something like:
>
>Select 1, 2, or 3: [1]
>and let the user select 1, 2 or 3 or after 'X' seconds
>exit and pass the choice to the script it's running. I'd 
>then check the result from the program and decide what program 
>the user wants to select. 
>
>I need to put this in a #/bin/sh script and run it on a linux box
>that doesn't have a lot of stuff ( like perl ) installed on it. 
>
>Is there a simple tool or shell trick that will let me do this? 
>If not, I'll see if I can write something in C that will do this...
>I'd prefer to find something else if possible.
>
>Thanks - jack 
>
>  
>

-- 
Jim Goode, SCSA (JGoode at GoToLearn.org)
Director IT and Software Development
972-543-4291, 1-877-465-3276
GoToLearn Inc., 2201 Avenue K, Suite A1, Plano, TX  75074
http://www.GoToLearn.org




More information about the Discuss mailing list