[SOLVED] How to run 'script' automatically on Konsole/Yakuake startup/new tab?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But I want to run the above automatically whenever I start Yakuake or open a new tab.
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?
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:
But I want to run the above automatically whenever I start Yakuake or open a new tab. 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?
Well, if you only ever want the script to run at user login, remove the "#!/bin/bash" from the top of it, and let your user session do it. That way, you can shove it into .profile or .bashrc, and it'll just run once, as everything else in .bashrc does.
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.
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.
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"?
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"?
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?
No, I misunderstood...my apologies. I didn't see BSD mentioned, and didn't know there was an actual program named "script", or what it did. So, totally ignore what i said.
- script will write your sessions to a file in your home directory naming them something like '30-Nov-11_00-11-12_shell.log'. Adjust this part to suit yourself - for example, you can append your sessions to one large file rather than creating a new one for every session with 'script -a /path/to/single_log_file'; or you can adjust where the files are written to - say, to /var/log/script/$USER_$(date +"%d-%b-%y_%H-%M-%S")_shell.log (make sure you've actually created /var/log/script and made it writable by others).
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'?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.