一段时间后如何使根外壳超时?


15

有没有一种方法可以使根shell(例如in gnome-terminal)“超时”,以便在一定时间内不发出任何命令后,shell退出?

我正在寻找可在bashFedora和kshOpenBSD 上使用的解决方案。

Answers:


23

您可以将TMOUT变量设置为以秒为单位的数字,如果没有运行命令,bash希望它在自动注销外壳之前等待。


5
TMOUT可用于bash和ksh。
卡姆(Camh)2011年

4
@camh Zsh也是,我希望任何现代的Shell都能支持它。
Arrowmaster

1
今天我学到了很棒的事情。
SHW

2

我知道这个问题与Bash&Ksh有关。但是我想我会为csh / tcsh发布类似的记录。

在FreeBSD上,默认的shell是tcsh。您可以使用autologouttcsh shell 的功能自动注销会话。

闲置活动一分钟后,以下将自动注销会话。

freebsd82# set -r autologout=’1′
(Wait one minute)
freebsd82# auto-logout
Connection to freebsd82 closed.

tcsh的(1)手册页描述它是这样的:

autologout (+)
     The first word is the number of minutes  of  inactivity  before
     automatic  logout.   The  optional second word is the number of
     minutes of inactivity before automatic locking.  When the shell
     automatically logs out, it prints `auto-logout', sets the vari-
     able logout to `automatic' and exits.  When the shell automati-
     cally locks, the user is required to enter his password to con-
     tinue working.  Five incorrect  attempts  result  in  automatic
     logout.  Set to `60' (automatic logout after 60 minutes, and no
     locking) by default in login and superuser shells, but  not  if
     the shell thinks it is running under a window system (i.e., the
     DISPLAY environment variable is set), the tty is  a  pseudo-tty
     (pty)  or  the shell was not so compiled (see the version shell
     variable).  See also the afsuser and logout shell variables.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.