Pregunta :Me gustaría finalizar mi shell de línea de comandos de Unix, cuando no ejecuto ningún comando durante N segundos. es decir, ¿cómo cerrar sesión automáticamente si no hay actividad en un shell de Linux?
Respuesta :La variable TMOUT en bash finalizará el shell si no hay actividad durante N segundos, como se explica a continuación.
# export TMOUT=N
- N está en segundos. Cuando no haya actividad durante N segundos, el shell finalizará.
Ejemplo :finalice el shell si no hay actividad durante 5 minutos.
# export TMOUT=300
Si no hay actividad en un shell en particular durante más de 5 minutos, terminará ese shell. No puede utilizar esta técnica para cerrar sesión en una sesión de GUI.
De 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.
TMOUT es útil cuando está ssh-ing a un servidor remoto y le gustaría cerrar sesión en el servidor remoto cuando no realiza ninguna actividad durante x número de segundos. Agregue el comando de exportación a su .bash_profile o .bashrc en el servidor remoto.