I am trying to enforce a policy that logs an idle user out of a bash shell session, even when they are in an active process like a script-based menu, or vi session.
我正在尝试执行一个策略,该策略将空闲用户从bash shell会话中记录下来,即使他们处于一个活动进程中,比如基于脚本的菜单或vi会话。
I have tried using "export TMOUT=x" where x is the number of seconds, but this only logs a user out if they are idle at the bash shell prompt.
我尝试过使用“export TMOUT=x”,其中x是秒数,但是只有当用户在bash shell提示符下空闲时,这才会记录用户。
Is there a bash script or any C code that I can run that will check what users have been idle for too long, and then stop all processes run by that user, and log them out?
是否有一个bash脚本或任何我可以运行的C代码来检查哪些用户已经闲置了太长时间,然后停止该用户运行的所有进程,并将它们注销?
Thanks
谢谢
Ryan
瑞安
1 个解决方案
#1
4
in bash
在bash中
w | tr -s " " | cut -d" " -f1,5 | tail -n+3
gives you a username/idletime pair for each shell. you can set up a cronjob using this information to logout the correct people. The idletime is the time since the last keystroke directly in the shell (and not the applications).
为每个shell提供用户名/idletime对。您可以使用此信息设置cronjob以注销正确的人员。空闲时间是自shell中最后一次击键以来的时间(而不是应用程序)。