Operating System - HP-UX
1834488 Members
3369 Online
110067 Solutions
New Discussion

Menu script with inactivity timer ?

 
SOLVED
Go to solution
Håkon Wøien
Occasional Contributor

Menu script with inactivity timer ?

I have written a simple helpdesk menu script which allows Helpdesk to reset passwords, reactivate users etc. in a Trusted HP-UX environment using sudo.

What I'm looking for is a simple way to exit the script after xx minutes of inactivity.

I was thinking about the TMOUT variable in posix shell, but since the script never returns to the prompt (read my_command) this don't help.

Any idea's on how to do this ?

Haakon
4 REPLIES 4
Mark Grant
Honored Contributor

Re: Menu script with inactivity timer ?

Try this trick.

Start a "sleep" in the background which is set to kill the menu script. If a menu option is selected, kill the sleep. Something like this

#all your menu code goes here
( sleep 10; kill $$)& # kill my menu script
# get an option
kill $! # kill last job run in the background
Never preceed any demonstration with anything more predictive than "watch this"
Borislav Perkov
Respected Contributor

Re: Menu script with inactivity timer ?

Hi,
try do do something with uptime or w command to estimate idle time.
Borislav
Jeroen Peereboom
Honored Contributor
Solution

Re: Menu script with inactivity timer ?

You can use the command
my_command=`line -t `

to read a line from input.
So if your menu is usually waiting for the next command to execute, you may use this command wirh a timeout, in which case my_command is empty.

Check the manpage for portability issues.
I don't know how to distinguish a timeout from a simple .

JP.
Steve Steel
Honored Contributor

Re: Menu script with inactivity timer ?

Hi

Jeroen is quite correct with

my_command==`line -t `

test like this

my_command=`line -t 3`
if [ -z "$my_command" ]
then
my_command=exit
fi
echo $my_command

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)