Operating System - HP-UX
1834882 Members
2309 Online
110071 Solutions
New Discussion

ksh script question:ONTIMEOUT .. ??

 
mooi-kuan
Advisor

ksh script question:ONTIMEOUT .. ??

I am looking for a way to trap timeout event in ksh script, how can I do that? ie is there an equivalent ON TIMEOUT GOTO ... statement in ksh shell script.

Thank you.

mk
1 REPLY 1
Steven Sim Kok Leong
Honored Contributor

Re: ksh script question:ONTIMEOUT .. ??

Hi,

You can execute a script based on trap 0, which occurs when a shell times out eg.

trap "/opt/scripts/myscript" 0

When the period specified in the TMOUT variable expires, your /opt/scripts/myscript will be executed.

Note however that by specifying a script for 0, you are overriding the global default action specified in /etc/profile which is:

trap "echo logout" 0

To set the TMOUT variable, eg.

In sh, ksh, bash: export TMOUT=300 (ie. 300 seconds)

In csh, tcsh: setenv TMOUT 300

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com