最新消息:阿啰哈,本人90后,目前单身,欢迎妹子们来撩!.(。→‿←。) 微信:frank01991

自动关闭非活动shell

Question: I would like to terminate my Unix command line shell, when I don’t execute any command for N number of seconds. i.e How to automatically log out if there is no activity in a Linux shell ?

Answer: TMOUT variable in bash will terminate the shell if there is no activity for N seconds as explained below.

# export TMOUT=N 
  • N is in seconds. When there is no activity for N seconds, the shell will be terminated.

Example: Terminate the shell if there is no activity for 5 minutes.

# export TMOUT=300 

If there is no activity in a particular shell for more than 5 minutes, then it will terminate that shell. You cannot use this technique to logout from a GUI session.

From man bash:

TMOUT  If  set  to  a  value greater than zero, TMOUT is treated as the default timeout for the read builtin.  
The select command terminates if input does not arrive after TMOUT seconds when input is coming from a terminal. 
In an interactive shell, the  value  is interpreted  as  the  number  of seconds to wait for input after issuing the primary prompt.  
Bash terminates after  waiting  for that number of seconds if input does not arrive. 

TMOUT is useful when you are ssh-ing to a remote server and would like to log out from the remote server when you don’t perform any activity for x number of seconds.Add the export command to your .bash_profile or .bashrc or /etc/profile on the remote-server

from: www.thegeekstuff.com

转载请注明:林志斌 » 自动关闭非活动shell

发表评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址