How to make `script` command loaded automatically on terminal login

3

1

script command allows to log gently everything that was put to console during session (like history but also displays results of commands). Everything is logged to file typescript.xxx

Now I want to run it in every terminal session that has been runned. I was trying to put script to bashrc but it falls into recursive loop (script is running it's own shell). Any ideas?

dfens

Posted 2013-03-13T16:32:51.640

Reputation: 141

Answers

1

add to

vi ~/.bash_profile

add

exec script

to the bottom (so it's the last thing loaded at login).

You will have to do this for every user though... but should get the job done.

SnakeDoc

Posted 2013-03-13T16:32:51.640

Reputation: 705

1This will only work if the user starts a login, non-interactive shell. Normally, opening a terminal runs an interactive shell so this will not work. Oh, and to do it for all users, just edit /etc/profile. – terdon – 2013-03-13T17:18:43.883

1

SnakeDoc's answer might work if you can force all shells to be login shells. If you are connecting ti a remote server via ssh for example. If this is your local machine and you want script to be run every time you open a terminal, the only way I can think of is using the terminal's settings.

For example, using my personal favorite terminal (terminator, on debian installable with sudo apt-get install terminator), you can set a specific command to be run when opening a terminal. Open ~/.config/terminator/config and add these lines to the [[default]] profile:

use_custom_command = True
custom_command = script -a

You can also set it up so that script is only run for a specific profile. Add these lines after the [[default]] profile:

[[script]]
  use_custom_command = True
  custom_command = script -a

This creates a new profile called script which you can run by executing terminator -p script.


On gnome-terminal, you can do the same as follows:

enter image description here enter image description here enter image description here

terdon

Posted 2013-03-13T16:32:51.640

Reputation: 45 216