1825803 Members
2700 Online
109687 Solutions
New Discussion

Shell timeout

 
Venkat Bala_2
Advisor

Shell timeout

Hi! all,

All the users use ksh in our HPUX 11i system. The .profile of all the users call another script in this form ". /usr/local/bin/abc" which has a "while true" loop so that the users will only get a menu when they login and when they exit the menu they will be logged out of the system. It has to be that way.

My question is how do I setup a shell timeout or idle timeout of say 30mts?

When I comment the script entry in the .profile and set the TMOUT value in the .profile. It works just fine as desired. But with the script entry enabled the TMOUT has no significance. The same happens when I set the TMOUT in /etc/profile.

Thank you,

-Venkat
12 REPLIES 12
RAC_1
Honored Contributor

Re: Shell timeout

You would be better off checking the login every 30 mins and checking the user's idle time (who -HT) and logging him out if it is more then 30 mins.

Anil
There is no substitute to HARDWORK
Prashant Zanwar_4
Respected Contributor

Re: Shell timeout

Naturally it has to be entered after the PS1 shell variable.

Also if you want telnet to timeout, you can use inetd.conf

telnetd -n240 like that.

Check your abc script, and you may put the value in abc script itslelf.

or

DO PS1=" <>"
and then do
TMOUT=90
and afterwards
call the script

Hope this helps
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Victor BERRIDGE
Honored Contributor

Re: Shell timeout

Hi,
Anil's suggestion is the way to go for TMOUT works for shell inactivity which is not your case (stuck in a menu)

All the best
Victor
RAC_1
Honored Contributor

Re: Shell timeout

Venkat,

I checked my reply and thought over it. If the abc script uses, while loop and comes tru all the time, even (who -HT) will not work because, the terminal is not idle. It is doing something. You script should take of these things.

I tried simple thing. Opened a vi session and waited. The idle time (who -HT

Anil
There is no substitute to HARDWORK
Venkat Bala_2
Advisor

Re: Shell timeout

Hi! again,

Prashant, I should have mentioned this in my first query but anyway, I had tried the option that you suggested PS1="XYZ" and then export TMOUT=30 in the abc script prior to asking this question in this forum. It didn't help. I even tried putting the TMOUT within the "while true" loop but didn't help. The inted parameter you talked about is not what I need.

Anil, I guess you already said what I was about to say for your response.

Any more ideas/thoughts?????

Thank you,

-Venkat
RAC_1
Honored Contributor

Re: Shell timeout

I just tried running the while true on a terminal. I tried
while true
do
bdf .
done

And watched the tty. Yes, it gives you idle time in who -HT. I am not sure about what idle time this refers to??--may be terminal activity. You can user who -HT in your case.

Anil
There is no substitute to HARDWORK
Patrick Wallek
Honored Contributor

Re: Shell timeout

The TMOUT variable will do you absolutely no good here. The TMOUT variable only works if the user is sitting at a shell prompt (like the $ prompt). Once a program or script is invoked, the TMOUT variable is essentially nullified. The reason being, in my opinion, that you wouldn't want to kill a session while it is doing something. Once you have invoked a script or program there is really no way for the parent process (the -ksh process in your case) to know what its child process(es) are doing.



Victor BERRIDGE
Honored Contributor

Re: Shell timeout

Hi,
As said in my previous post since your main shell has called a menu the TMOUT will not apply because its not "idle" anymore so as Anil suggest your only solution is to look through who -HT that shows tty idle and not shell idle...

I have a case here at work:
# who -HT
NAME LINE TIME IDLE PID COMMENTS
vbe - ttyp1 Sep 27 20:30 old 24719
vbe - ttyp2 Sep 27 20:30 . 24734
vbe - ttyp3 Sep 27 20:30 old 24752
oper + ttyr2 Sep 29 12:18 4:52 22237
tollerju + pty/ttys6 Sep 29 10:49 1:34 17083
oper + pty/ttysb Sep 29 08:25 5:50 16220
porteni + pty/ttyt7 Sep 29 08:49 7:37 8103
rolohugo + pty/ttyt8 Sep 27 08:38 old 5065
revazgil + pty/ttyu3 Sep 29 08:46 0:55 5446
tounsifa + pty/ttyu7 Sep 29 08:49 2:09 8385
revazgil + pty/ttyv4 Sep 29 09:11 2:11 24022
# ps -ef |grep toller
vbe 9539 24734 1 18:24:45 ttyp2 0:00 grep toller
tollerju 17083 17082 0 10:49:31 ttys6 0:01 /opt/oracle/product/7.2.3/bin/iap30 -c /opt/oracle
/product/7
tollerju 17425 17083 0 10:49:40 ? 0:14 oraclePXPX (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTO
COL=beq)))
#
# finger tollerju
Login name: tollerju (messages off) In real life: TOLLER Juliana
Bldg: 123
Directory: /users/ocpa/tollerju Shell: /usr/bin/sh
On since Sep 29 10:49:37 on pty/ttys6 from 160.53.84.208
1 hour 37 minutes Idle Time
No Plan.

I know that when these people connect themselves they launch a shell that calls a menu that calls a Forms3 menu...


All the best
Victor
John Palmer
Honored Contributor

Re: Shell timeout

Two ideas...
1. Run a regular cron job to identify and kill any terminal sessions that have been inactive for > 30 mins. The 'w' command displays terminal idle time in minutes and seconds.

2. Have a background process monitor the menu process. The menu can't do anything because it's sitting on a 'read' statement waiting for terminal input.
Just prior to the 'read' run a background script which sleeps for 30 minutes then kills its parent.
If the menu is reactivated by the user typing an option, kill the background script.

The first option is probably easier to implement.

Regards,
John
Muthukumar_5
Honored Contributor

Re: Shell timeout

We are having only one option as checking the idleness of shell login there.

I have tested by putting infinite loop on /etc/profile and .profile and idleness are logged on who and w commands.

If we start a process ( infinite loop ) on /etc/profile or .profile so that specific shell process can be controlled in another terminal of same user or super user to manage that particular process.

Because we can not start that specific process in background so that user can not do operation on menu's. IT can be done on foreground only.

Get the idleness of shell as,

who -Ru or who -HT
or
w command or w -h

Write a script and do cron it so that it will run for every one minute to check idleness of shell process and kill that shell process with some message to that user usign wall command with tty ( can get with who or w ).

Or run manual mode to check that with shell script.

HTH.
Easy to suggest when don't know about the problem!
Venkat Bala_2
Advisor

Re: Shell timeout

Thank you everyone for your replies. I thought I would check the forum techies before I came to the conclusion that I've write a shell script and run a cron job every minute.

I guess that seems to be the only option.

-Venkat
Venkat Bala_2
Advisor

Re: Shell timeout

I'll write a shell script and setup a cron job every minute.

Thank you everyone for your time and inputs.

-Venkat