|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Trappable Signals
Hi All,
I'm looking for a way to have a script prompt the user for some input but only wait a certain amount of time (20 secs) before assuming a default response. The approach I'm trying is to start a background timer process that sleeps for 20 seconds then sends a signal to the parent. A trap in the parent should pick up the signal and allow me to bypass the read that's requesting input. The problem I'm having with this is that the signal my background timer is sending is always ignored until the read command has terminated. Obviously this isn't what I want. So, does anyone know of:
Steve (I'm on AIX 5.1 using ksh if that helps) |
|
#2
|
||||
|
||||
|
Try using eread from here.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
Thanks for that.
eread seems to be using basically the same technique as me but instead of the ALRM, USR1 or USR2 signals that I've been using it's using INT. Simple really. I would have got there eventually. If anyone is interested this is what I've ended up with: Code:
# Trap INT signals but do nothing with them trap 'true' INT # Display some stuff to the user ... # Start a background timer that sends an INT after 20 seconds sleep 20 && kill -s INT $$ > /dev/null 2>&1 & # Now get user feedback read response?"Response? : " # Kill the timer kill $! 2> /dev/null # Act on the response ... Steve |
|
#4
|
|||
|
|||
|
I propose another solution which makes use of the noncanonical mode. I have tested it on AIX 5 2.
: echo Press any key within 20 sec. to start input stty -echo -icanon min 0 time 200 # 200 tenths of second ANS=$(dd count=1 bs=100 2>/dev/null) stty echo icanon if [ -z "$ANS" ] ; then echo no response, default values used else echo input required values fi Regards |
|
#5
|
|||
|
|||
|
Very handy. Many thanks.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Trappable Signals |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|