Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make menu timeout 4

Status
Not open for further replies.

lpblauen

Technical User
Dec 2, 2004
193
US
I have a menu for the helpdesk that gives them commands they can run. The problem is when they login and just sit on the menu. I need it to time out after 30 minutes of no activity. In the .profile I have a time out for the user id but when they are in the menu they don't time out. This is what is in the .profile
TO=1800
TIMEOUT=$TO
TMOUT=$TO
export TIMEOUT TMOUT

What do I need to put in the menu to make it time out.
here is the menu
# Name: helpmenu

trap 'print "Problem with Help Desk menu "; exit' HUP INT QUIT STOP

print " 1) Add users"
print " 2) Change password"
print " 3) Logout "
read sel?
while :
do
case "$sel" in
1) . set_accounts
;;
2) . newpass
;;
3) return
;;
esac
print " 1) Add users"
print " 2) Change password"
print " 3) Logout"
read sel?
done
 

If this is a Bash script, you can specify the "-t timeout" option of the "read" command.

 

Korn shell has the very same "-t {seconds}" option as does the Bash shell.
 
Try this...
Code:
#!/bin/ksh
# Name: helpmenu

trap 'print "Problem with Help Desk menu "; exit' HUP INT QUIT STOP

MIN=0
TIME=200

while :
do
   print
   print " 1) Add users"
   print " 2) Change password"
   print " 3) Logout "
   print

[b]   # Save old terminal settings
   OLDSTTY=`stty -g`

   # Set terminal read to timeout
   stty -icanon min ${MIN} time ${TIME}
[/b]
   read SEL?" Option: "; RC=$?
[b]
   # Set terminal back to old values
   stty "${OLDSTTY}"

   (( RC )) && print "Timed out, exiting" && exit
[/b]
   case "$SEL" in
      1)   . set_accounts
           ;;
      2)   . newpass
           ;;
      3)   return
           ;;
      *)   print
           print "Invalid Option ${SEL}, please try again!"
           ;;
   esac
   print
done
 
Sambones the script works great. 1 question.
MIN=0
TIME=200

If I set min to 5 the script locks up. If I set time to 500
it still stops to fast. I need the script to time out after 30 minutes. How would I set that up? Please explain the min and time variables. Is min in minutes and time in seconds?
 
Please explain the min and time variables
man stty

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ok I still don't understand it. What does this mean?
Sets the value of min or time to number. MIN and TIME are used in Non-Canonical mode input processing (-icanon).
 
MIN is a number of characters
TIME is a number of 100 milliseconds (ie tenth of secon)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
so if I read this right. I set min to 0 so it waits for a input. and I set time 10x60 to get 1 minute then 600x30 to get 30 minutes? = 18000
 
I just reset the min to 0 and time to 1200000 and the program still stops in 15 seconds. what am I doing wrong.
 
The [tt]MIN[/tt] of zero means it can timeout or return with no characters. If you set it to 1, the [tt]read[/tt] will only return if it has 1 or more characters. That's the minimun number of characters it needs to read.

And the [tt]TIME[/tt] is in tenths of seconds as already mentioned.
 
There's probably a maximum acceptable value for [tt]TIME[/tt]. I don't know what that is.
 
A different approach:
Code:
trap 'print "Problem with Help Desk menu "; exit' HUP INT QUIT STOP
while
        print " 1) Add users"
        print " 2) Change password"
        print " 3) Logout "
        (sleep $TIMEOUT; kill -15 $$ >/dev/null 2>&1) &
do      read sel?
        kill -9 $! >/dev/null 2>&1
        case "$sel" in
                1) . set_accounts
                ;;
                2) . newpass
                ;;
                3)  return
                ;;
        esac
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PMV this works great. Thanks..... Now for more testing....
I got it to wait 2 minutes now to increase the time and wrok towards 30 minutes.
 
One last question. How can I keep someone from doing a
ctrl-c out of the menu program. If they do it I want them logged out completely.
 
change your first line:

trap 'print "Problem with Help Desk menu "; logout' HUP INT QUIT STOP

that should do it


HTH,

p5wizard
 
That kinda works. It does not let ctrl-c do anything but the when I do option 3 to logout it drops me to a $prompt and the id is still running. I have in the .profile to run helpmenu then the next line is exit. What should happen is the oper logs in and gets the menu. Any key but the ones on the menu should return invaild option. When they are done they use option 3 and it logs them out. If they do a ctrl-c the menu returns a invalid key and redraws the menu. Now if they do option 3 they drop to a $prompt and not logged out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top