GNU/Linux >> Linux Esercitazione >  >> Linux

TMOUT – Esce automaticamente dalla shell Unix quando non c'è attività

Domanda :Vorrei terminare la mia shell della riga di comando Unix, quando non eseguo alcun comando per un numero N di secondi. cioè come disconnettersi automaticamente se non c'è attività in una shell Linux?

Rispondi :la variabile TMOUT in bash terminerà la shell se non c'è attività per N secondi come spiegato di seguito.

# export TMOUT=N
  • N è in secondi. Quando non c'è attività per N secondi, la shell verrà terminata.

Esempio :termina la shell se non ci sono attività per 5 minuti.

# export TMOUT=300

Se non c'è attività in una particolare shell per più di 5 minuti, la shell terminerà. Non è possibile utilizzare questa tecnica per disconnettersi da una sessione GUI.

Da 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 è utile quando si esegue un ssh-ing su un server remoto e si desidera disconnettersi dal server remoto quando non si esegue alcuna attività per un numero x di secondi. Aggiungi il comando export al tuo .bash_profile o .bashrc sul server remoto.


Linux
  1. Ripeti un comando Unix ogni X secondi per sempre?

  2. Somma una colonna di numeri nella shell Unix

  3. Come impostare in modo permanente $ PATH su Linux/Unix?

  4. Problema con la variabile della shell durante il tentativo di mkdir

  5. Perché LXC quando c'è linux-vserver?

Perché questa pipeline di shell termina?

Quando avvolgere le virgolette attorno a una variabile di shell?

restituire il valore dallo script python allo script shell

C'è un modo per abilitare minicom linewrap per impostazione predefinita

Qual è l'ambito delle variabili esportate nella shell Unix?

Esiste una distribuzione Linux certificata UNIX?