UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 13th, 2004, 10:58 AM
dev0173 dev0173 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 18 dev0173 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
  1. A signal (other than -9) that will actually interrupt a "read", or
  2. A better way of doing what I want?
Many thanks

Steve
(I'm on AIX 5.1 using ksh if that helps)

Reply With Quote
  #2  
Old December 13th, 2004, 12:05 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 44 m 37 sec
Reputation Power: 797
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

Reply With Quote
  #3  
Old December 14th, 2004, 03:24 AM
dev0173 dev0173 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 18 dev0173 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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
...
This code will wait 20 seconds for a user response. If non is received then $response will be null and you can imply whatever you want from that.

Steve

Reply With Quote
  #4  
Old December 17th, 2004, 04:01 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
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

Reply With Quote
  #5  
Old December 17th, 2004, 04:24 AM
dev0173 dev0173 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 18 dev0173 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Very handy. Many thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Trappable Signals


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway