没有活动时自动退出 Linux Shell -- TMOUT
【摘要】 当我在 N 秒内没有执行任何命令时,我想终止我的 Unix 命令行 shell。即如果Linux shell 中没有活动,如何自动注销?
如果 N 秒内没有活动,bash 中的 TMOUT 变量将终止 shell
当我在 N 秒内没有执行任何命令时,我想终止我的 Unix 命令行 shell。即如果Linux shell 中没有活动,如何自动注销?
如果 N 秒内没有活动,bash 中的 TMOUT 变量将终止 shell,如下所述。
# export TMOUT=N
- N 以秒为单位。当 N 秒没有活动时,shell 将被终止。
示例:如果 5 分钟内没有任何活动,则终止 shell。
# export TMOUT=300
如果特定 shell 中超过 5 分钟没有活动,那么它将终止该 shell。您不能使用此技术从 GUI 会话中注销。
来自 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 termi‐
nates 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.
当您通过 ssh 连接到远程服务器并且想要在 x 秒内不执行任何活动时从远程服务器注销时,TMOUT 很有用。
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)