Operating System - HP-UX
1839977 Members
3609 Online
110158 Solutions
New Discussion

Re: Asking for input with timeout (Shell scripting)

 
SOLVED
Go to solution
Klaas D. Eenkhoorn
Regular Advisor

Asking for input with timeout (Shell scripting)

Dear All,

I have a question about shell scripting, how can i ask for input from a user with a timout ? For example: I want to ask the user if he/she wants to start changing his/her password but if he/she does not respond within 10 sec by pressing a key the script shoud continue.

Kl@@s
2 REPLIES 2
Chris Wilshaw
Honored Contributor
Solution

Re: Asking for input with timeout (Shell scripting)

you can use the "line" command for this

line -t 10

will wait for a response, then force continuation of the script if nothing is done by the user.
Mark Grant
Honored Contributor

Re: Asking for input with timeout (Shell scripting)

Try this

Only timing out a "read" is difficult so use this script to return a read. In other words, call this script "tmoutread" and then withion your script go

result=`tmoutread`

#!/bin/sh
( sleep 3; kill $$ )&
read result
kill $!
echo $result

Change the value of sleep to extend the timeout
Never preceed any demonstration with anything more predictive than "watch this"