22

We have here a read only Bash variable. I am not allowed to unset that variable.

$ echo $TMOUT
1800

As a workaround I wrote those lines (that my session don't exit)

#!/usr/bin/perl

$|++;
while (1) { print "\e[0n"; sleep 120; }

Is there an official package (rpm) that does similar (like above Perl code) in a CentOS7/RHEL7 repository? I don't like to open up a vim editor, I wish a command.

αғsнιη
  • 40,939
  • 15
  • 71
  • 114
Sybil
  • 1,653
  • 5
  • 19
  • 37
  • 7
    Usual solution to this is just run `cat` when stepping away from your session. And then ^C it on your return. – steve Aug 10 '15 at 14:36
  • 1
    I imposed a similar rule because I had people in my team that left terminals open for weeks in a row. Whilst I do agree 1800 is kinda of low, it must be there for some reason. People tend to notice deviations to the usual...yours sessions will stand out like a sore thumb. – Rui F Ribeiro Jan 29 '16 at 09:04
  • 1
    when it's read-only, type: `exec env TMOUT=0 bash` – nightshift Aug 19 '18 at 03:39
  • I've found that simply [not closing the terminal on exit](https://askubuntu.com/questions/630698/how-can-i-keep-the-gnome-terminal-open-after-a-program-closes) works around most of the reasons I hate this "feature". Trying to remember to `cat` is just setting yourself up to fail. – candied_orange Jan 12 '23 at 20:23

6 Answers6

23

Add this to the start of your .bash_profile ?

if [ ! -z "$TMOUT" ]; then
  env -i bash --init-file ~/.bash_profile
fi

Beware the wrath of the sysadmins if you leave a gazillion old sessions running as a result of defeating their timeout rulings.

steve
  • 21,582
  • 5
  • 48
  • 75
9

Here is the thing,
When the session variable is "Read Only" you have to replace the current shell process with the command by "exec"
So, the Answer to your question is:

$> exec env TMOUT=0 bash

But I recommend setting a higher timeout value

$> exec env TMOUT=3600 bash
Alper t. Turker
  • 221
  • 2
  • 4
6

You can issue perl commands from the command line...

perl -e '$|++; while (1) { print "\e[0n"; sleep 120; }'

or you could do the same in shell (a sh/bash example):

while sleep 120; do printf '\33[0n'; done

Or you could use watch:

watch -n 120 printf '\33[0n'

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Drav Sloan
  • 14,145
  • 4
  • 45
  • 43
  • what is `printf '\33[0n'`? i know what the command line `printf` is. but what is being printed? – Trevor Boyd Smith Mar 13 '18 at 14:35
  • 1
    `\33` is shorthand for the escape key `[0n` is not a known ANSI escape code, I imagine it was a typo and should of been `[0m` which resets the terminal colour for apps/terminals/tty's that support ANSI escape codes. – Drav Sloan Mar 14 '18 at 18:01
4

I my case, it is defined in /etc/profile.d/bash_autologout.sh:

TMOUT=1800
readonly TMOUT
export TMOUT

To find it, I did:

sudo find /etc/ -name "*" | xargs sudo grep "TMOUT" 2>&1 | grep -v "filter..."
dagos
  • 41
  • 1
0

export TMOUT=0

top

You will have some activity and your session will stay and you could see how long it runs.

-1

Why aren't you switching to non-interactive session?

# TMOUT=0
-bash: TMOUT: readonly variable
# unset TMOUT
-bash: unset: TMOUT: cannot unset: readonly variable
# su
# export TMOUT=10
# unset TMOUT
# 
Mathieu
  • 2,679
  • 1
  • 20
  • 25