11

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.

3
  • 4
    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
  • 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. Jan 29 '16 at 9:04
  • when it's read-only, type: exec env TMOUT=0 bash
    – nightshift
    Aug 19 '18 at 3:39
15

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.

2
  • This is truly EVIL!
    – Ahi Tuna
    Dec 20 '19 at 15:47
  • 2
    The -i argument wipes out the environment. You can be more specific and only unset a single variable like so: env -u TMOUT bash --init-file ~/.bash_profile Mar 18 '20 at 9:59
5

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'

2
  • what is printf '\33[0n'? i know what the command line printf is. but what is being printed? Mar 13 '18 at 14:35
  • 1
    \33 is shorthand for the escape key <esc>[0n is not a known ANSI escape code, I imagine it was a typo and should of been <esc>[0m which resets the terminal colour for apps/terminals/tty's that support ANSI escape codes.
    – Drav Sloan
    Mar 14 '18 at 18:01
5

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
1
  • If I add exec env TMOUT=0 bash to .bashrc, is it going to work in the same way?
    – notilas
    Nov 15 '20 at 5:41
0

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
# 
0

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..."
0

export TMOUT=0

top

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.