How to run 'script' automatically on Konsole/Yakuake startup/new tab?
What I want to achieve is be able to record my terminal sessions to file automatically whenever I use Yakuake/Konsole.
It's easy to achieve if at the start of my session I do: Quote:
Using .bashrc does not work because it creates endless loop as 'script' opens a new session, which in turn reads .bashrc and starts another 'script' and so on. So presumably I need to script Yakuake/Konsole somehow to run 'script' once as a new tab gets opened. The question is how? |
Quote:
You might also look into putting in the system wide profile (usually /etc/profile), that gets executed at each login. You can put things at the bottom, and probably get away with putting the entire script contents in that file, also eliminating the endless-loop problem. |
Hello TB0ne,
Thank you for the reply. I'm afraid though that I either do not understand your solution or you misunderstood my question - I do not mean some random script I made up, I'm talking about a rather unfortunately named program named 'script' that is part of bsdutils together with renice, wall, scriptreplay and logger. The problem, as I see it, is that whenever 'script' is run, it opens another shell. So if I have an instruction in bashrc to run script, this new shell reads it and starts another script, which opens another shell, which opens another script and so on. "Inception". So basically it seems that I need to have Yakuake/Konsole calling /usr/bin/script instead of /bin/bash when opening a new tab. Or did I not understand your answer? |
As I understood, script "script" launches a new bash shell. What if you start it like "bash --norc `which script` arg1 arg2" instead of "script arg1 arg2"?
|
Quote:
Code:
/usr/bin/script: /usr/bin/script: cannot execute binary file |
Quote:
|
Well, OK. You can make a simple script like the following, and make terminal emulator run it instead of /bin/bash.
Code:
#!/bin/bash |
I did it! I did it! On my own!
So if someone wants to record their terminal sessions automatically (including SSH sessions(!)) using script utility here is how: Add the following line at the end of /etc/bash.bashrc file (or to .bashrc in your home if you only want your own sessions to be recorded): Code:
test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f $HOME/$(date +"%d-%b-%y_%H-%M-%S")_shell.log) Now when you open new terminal you'll see: Code:
Script started, file is /home/username/file_name.log We test for Code:
ps -ocommand= -p $PPID Code:
awk '{print $1}' If the test is true we exit, if not - we run script: Code:
script -f $HOME/$(date +"%d-%b-%y_%H-%M-%S")_shell.log The thread title is somewhat misleading now as this solution is terminal-agnostic and will work with everything not just Yakuake/Konsole. Should be something like:'How to automatically record all your terminal sessions with script utility'? |
All times are GMT -5. The time now is 04:27 PM. |